Example #1
0
// Game loop renders, and calls update etc.
void game_loop()
{
  camera_control();
  
  renderer::reset();
  renderer::clear();
  
  simple_shader.set_raw_data("worldMat", caff_math::matrix44_get_data(world), sizeof(caff_math::matrix44));
  simple_shader.set_raw_data("viewMat",  caff_math::matrix44_get_data(view),  sizeof(caff_math::matrix44));
  simple_shader.set_raw_data("projMat",  caff_math::matrix44_get_data(proj),  sizeof(caff_math::matrix44));

  simple_shader.set_texture("mip0", dynamic_mips.at(0));
  simple_shader.set_texture("mip1", dynamic_mips.at(1));
  simple_shader.set_texture("mip2", dynamic_mips.at(2));
  simple_shader.set_texture("mip3", dynamic_mips.at(3));
  simple_shader.set_texture("mip4", dynamic_mips.at(4));
  simple_shader.set_texture("mip5", dynamic_mips.at(5));
  
  renderer::draw(simple_shader, vert_fmt, obj_plane);
  
  // SDL Things
  window.flip_buffer();
  
  window.think();
  input.think();
  sdl::message_pump();
}
Example #2
0
void SceneEdit::handle_input() {

    if (input->mouse->left_clicked()) {
        if(!destruct_mode) {
            if(edit_chess) {
                chess_board->set_type(chess_board->selected_on.x,
                                      chess_board->selected_on.z,chess_type);
            } else {
                chess_board->set_type(chess_board->selected_on.x,
                                      chess_board->selected_on.y,
                                      chess_board->selected_on.z,type);
            }
        } else {
            if(edit_chess) {
                chess_board->set_type(chess_board->selected_on.x,
                                      chess_board->selected_on.z,-chess_type);
            } else {
                chess_board->set_type(chess_board->selected_cube.x,
                                      chess_board->selected_cube.y,
                                      chess_board->selected_cube.z,0);
            }
        }

    }

    if(input->keyboard->get('Q')) {
        edit_chess^=1;
    }
    /*
    if(input->keyboard->get('S')){
    	//chess_board->save_board(CM::folder_path+"game/chess/chessBoard/board.txt");
    	chess_board->save_board(chess_board->dir_path+"chessBoard/board.txt");
    }
    if(input->keyboard->get('L')){
    	//chess_board->load_board(CM::folder_path+"game/chess/chessBoard/board.txt");
    	chess_board->load_board(chess_board->dir_path+"chessBoard/board.txt");
    }
    */
    if(input->keyboard->get(Input::KeyCode::Plus)) {
        if(edit_chess) {
            if(chess_type<(int)chess_board->pieces.size()) {
                chess_type++;
            }
        } else {
            if(type<chess_board->cube_type_num)type++;
        }

    }
    if(input->keyboard->get(Input::KeyCode::Minus)) {
        if(edit_chess) {
            if(chess_type>0)chess_type--;
        } else {
            if(type>0)type--;
        }
    }
    camera_control();
}
Example #3
0
//Called whenever a key on the keyboard was pressed.
//The key is given by the ''key'' parameter, which is in ASCII.
//It's often a good idea to have the escape key (ASCII value 27) call glutLeaveMainLoop() to 
//exit the program.
void keyboard(unsigned char key, int x, int y)
{
	if(key==27){
		objects_delete();
		glutLeaveMainLoop();
	}else if(key==32){
		g_bDrawLookatPoint = !g_bDrawLookatPoint;
		printf("Target: %f, %f, %f\n", g_camTarget.x, g_camTarget.y, g_camTarget.z);
		printf("Position: %f, %f, %f\n", g_sphereCamRelPos.x, g_sphereCamRelPos.y, g_sphereCamRelPos.z);
	}else{
		camera_control(key);
	}

	glutPostRedisplay();
}
Example #4
0
long redrobd_ctrl_thread::cyclic_execute(void)
{
  try {
    // Check if shutdown was selected (DIP-switch)
    if ( (!m_shutdown_select) && (m_hw_cfg_auto->select_shutdown()) ) {
      redrobd_log_writeln(get_name() + " : Shutdown selected");
      // Send signal to main process
      if (send_signal_self(SIG_TERMINATE_DAEMON) != DAEMON_SUCCESS) {
	THROW_EXP(REDROBD_LINUX_ERROR, REDROBD_SIGNAL_OPERATION_FAILED,
		  "Error sending shutdown signal for thread %s",
		  get_name().c_str());   
      }
      m_shutdown_select = true; // Only signal once
    }

    // Check battery voltage
    if ( !battery_voltage_ok() ) {
      redrobd_led_bat_low(true);   // Turn status LED on
    }
    else {
      redrobd_led_bat_low(false);  // Turn status LED off
    }

    // Check system stats
    check_system_stats();

    // Check state and status of created threads
    check_thread_run_status();

    // Check remote control steering
    uint16_t steering = get_remote_steering();

    // Do motor control
    switch (steering) {
    case REDROBD_RC_STEER_NONE:
      motor_control(REDROBD_MC_NONE);
      break;
    case REDROBD_RC_STEER_FORWARD:
      if (m_verbose) {
	redrobd_log_writeln(get_name() + " : steer forward");
      }
      motor_control(REDROBD_MC_FORWARD);
      break;
    case REDROBD_RC_STEER_REVERSE:
      if (m_verbose) {
	redrobd_log_writeln(get_name() + " : steer reverse");
      }
      motor_control(REDROBD_MC_REVERSE);
      break; 
    case REDROBD_RC_STEER_RIGHT:      
      if (m_verbose) {
	redrobd_log_writeln(get_name() + " : steer right");
      }
      motor_control(REDROBD_MC_RIGHT);
      break;
    case REDROBD_RC_STEER_LEFT:
      if (m_verbose) {
	redrobd_log_writeln(get_name() + " : steer left");
      }
      motor_control(REDROBD_MC_LEFT);
      break;
    default:
      // All other steerings are ignored for now
       ostringstream oss_msg;
       oss_msg << get_name()
	       << " : Got undefined steering = 0x"
	       << hex << setw(4) << setfill('0') << (unsigned)steering;
       redrobd_log_writeln(oss_msg.str());
       oss_msg.str("");

       motor_control(REDROBD_MC_STOP); 
    }

    // Check remote control camera code
    uint16_t camera_code = m_rc_net_auto->get_camera_code();

    // Do camera control
    switch (camera_code) {
    case REDROBD_RC_CAMERA_NONE:
      camera_control(REDROBD_CC_NONE);
      break;
    case REDROBD_RC_CAMERA_STOP_STREAM:
      camera_control(REDROBD_CC_STOP_STREAM);
      break;
    case REDROBD_RC_CAMERA_START_STREAM:
      camera_control(REDROBD_CC_START_STREAM);
      break; 
    default:
      // All other camera codes are ignored for now
       ostringstream oss_msg;
       oss_msg << get_name()
	       << " : Got undefined camera code = 0x"
	       << hex << setw(4) << setfill('0') << (unsigned)steering;
       redrobd_log_writeln(oss_msg.str());
       oss_msg.str("");
    }

    return THREAD_SUCCESS;
  }
  catch (excep &exp) {
    syslog_error(redrobd_error_syslog_string(exp).c_str());
    return THREAD_INTERNAL_ERROR;
  }
  catch (...) {
    syslog_error("redrobd_ctrl_thread::cyclic_execute->Unexpected exception");
    return THREAD_INTERNAL_ERROR;
  }
}
Example #5
0
void ScenePlayTD::handle_input() {
	camera_control();
	if (input->mouse->left_clicked()) {//->left_pressed()

		Cube *selected_cube =  field->map->get_cube(field->map->selected_cube.x,
													field->map->selected_cube.y,
													field->map->selected_cube.z);


		if(Building *selected_building = dynamic_cast<Building *>(selected_cube) ){
			std::cout<<"building selected. hp="<<selected_building->get_hp()
					<<"/"<<selected_building->get_max_hp()<<std::endl;
			field->unit_controller->select_unit(selected_building);
			return;
		}else{
			field->unit_controller->deselect_unit();
		}

		if(mode == constructing){
			//std::cout<<"constructing!"<<std::endl;
			//BuildingCreator* creator2=BuildingCreator::get_cur_object();
			//constructing_building = creator2->create("Tower");
			if(!constructing_building)return;
			if(constructing_building->buildable(constructing_building->get_pos_int().x,
					constructing_building->get_pos_int().y,
					constructing_building->get_pos_int().z)){
				if(!PlayerController::get_cur_object()->get_cur_player()
						->modify_resource(constructing_building->get_build_cost())){
					delete constructing_building;
					constructing_building = 0;
					mode = normal;
					return;
				}
				constructing_building->create_building();
				constructing_building = 0;
				mode = normal;
			}else{
				delete constructing_building;
				constructing_building = 0;
				mode = normal;
			}

			/*
			map->push_CubeEX(map->selected_on.x,
							   map->selected_on.y,
							   map->selected_on.z,
							   building);
			*/
		}else if(mode == removing){
			field->map->set_cube_type(field->map->selected_cube.x,
									  field->map->selected_cube.y,
									  field->map->selected_cube.z,
							   Cube::cubeNull);
		}else{
			/*field->map->set_cube_type(field->map->selected_on.x,
									  field->map->selected_on.y,
									  field->map->selected_on.z,
							   Cube::dirt);*/
		}

	}
	if (input->keyboard->pressed_char('w')) {
		field->map->dp_map->display_height_alter(1, thread_pool);
	}
	if (input->keyboard->pressed_char('s')) {
		field->map->dp_map->display_height_alter(-1, thread_pool);
	}
	if (input->keyboard->get('I')) {
		field->map->dp_map->display_range += 1;
	}

	if (input->keyboard->get('E')) {
		if(!UI->check_mode(UI::Mode::EDIT)){
			UI->Enable_Mode(UI::Mode::EDIT);
		}else{
			UI->Disable_Mode(UI::Mode::EDIT);
		}
	}
	if(input->keyboard->get('S')){
		UI->Save_script("files/AgeOfCube/playTD/UI/playTD_UI.txt");
	}else if(input->keyboard->get('L')){
			//delete UI;
		UI = new UI::UI("files/AgeOfCube/playTD/UI/playTD_UI.txt");
	}
	if (input->keyboard->get('V')) {
		if(mode == normal){
			mode = removing;
		}
		else if(mode == removing){
			mode = normal;
		}
	}
	if (input->keyboard->get('K')) {
		if (field->map->dp_map->display_range > 1)
			field->map->dp_map->display_range -= 1;
		else
			field->map->dp_map->display_range = 0;
	}
	if (input->keyboard->pressed('B')) {
		glm::ivec3 pos = Map::convert_position(camera->look_at);
		if (!field->map->get_cube_type(pos.x, pos.y, pos.z)) {
			if (field->map->set_cube_type(pos.x, pos.y, pos.z, Cube::stone)) {
				//dmap->update_map(pos);
			}
		}
	}
	if(input->keyboard->get('S')){
		UI->Save_script("files/AgeOfCube/editMap/UI/editMapUI.txt");
	}
	if(input->keyboard->get('P')){
		pause_timer^=1;
	}
	if (input->keyboard->pressed('V')) {
		glm::ivec3 pos = Map::convert_position(camera->look_at);
		if (field->map->get_cube_type(pos.x, pos.y, pos.z)) {
			Cube *cube=field->map->get_cube(pos.x,pos.y,pos.z);
			std::cout<<"cube name="<<cube->get_name()<<std::endl;
			if (field->map->set_cube_type(pos.x, pos.y, pos.z, 0)) {
				//dmap->update_map(pos);
			}
		}

	}
	if (input->keyboard->pressed(GLFW_KEY_UP)) {
		if (lightControl->shadow_dis > 0.01)
			lightControl->shadow_dis *= 0.98;
	}
	if (input->keyboard->pressed(GLFW_KEY_DOWN)) {
		if (lightControl->shadow_dis < 30.0)
			lightControl->shadow_dis *= 1.01;
	}
}