Jump to content

  • Log In with Google      Sign In   
  • Create Account

pythedev

Member Since 11 Nov 2009
Offline Last Active May 20 2012 03:19 PM

Topics I've Started

Spaceship movement parameters update

20 May 2012 - 10:27 AM

Hello!

I'm making a pretty basic spaceship game. Every time I update or change a main parameter, that affects others(acceleration, acceleration change speed, direction change speed) then I want to recalculate all parameters.

I have the following parameters at the beginning of the movement:

		long currentTime = System.currentTimeMillis();
		double timeDelta = (currentTime - lastUpdate) / 1000.0;
		lastUpdate = currentTime;
		double posX = params.get(Param.POS_X);
		double posY = params.get(Param.POS_Y);
		double accX = params.get(Param.SPEED_X_PIX_SEC); // ship acceleration x axis.
		double accY = params.get(Param.SPEED_Y_PIX_SEC); // ship acceleration y axis.
		double dir = params.get(Param.DIRECTION_RAD);
		double dirSpeed = params.get(Param.DIRECTION_SPEED_RAD_SEC);
		double thrust = params.get(Param.THRUST_PIX_SEC); // acceleration change speed. Depends on direction change.

And now I want to set the parameter values to what they should be after a certain amount of time has passed(timeDelta). Two parameters don't need updating since they are there only to affect other parameters - thrust and dirSpeed.
It would be a piece of cake to figure it out when there would not be any direction change...

hibernate - one to many relationship in the same table.

21 April 2012 - 11:42 AM

Hello!

I have a posgresql database where information about rivers are stored.

CREATE TABLE river_data
(
  id_river integer,
  id_destination integer,
  river_name character varying(15),
... many other fields
)
WITH (
  OIDS=FALSE
);
ALTER TABLE river_data
  OWNER TO xyz;

Getting information about one single river without its subrivers works well:

@Entity
@Table(name = "river_data")
public class RiverData {
	@Id
	@Column (name = "id_river")
	private int riverId;
	@Column (name = "river_name")
	private String riverName;
	@Column (name = "id_destination")
	private int destinationRiverId;
	public int getRiverId() {
		return riverId;
	}
	public String getRiverName() {
		return riverName;
	}
	public int getDestinationRiverId() {
		return destinationRiverId;
	}
}

Now I want to retrieve information about a river with a list(collection) of its subrivers, but I don't know how. All subrivers should have their destination_id equal to the main river_id. The current code looks like this(it crashes the sql server):

@Entity
@Table(name = "river_data")
public class RiverDataWithSubRivers {
	@Id
	@Column (name = "id_river")
	private int riverId;
	@Column (name = "river_name")
	private String riverName;
	@Column (name = "id_destination")
	private int destinationRiverId;
	@OneToMany
	@JoinColumn(name="id_destination") // TODO: problem is here.
	private Collection<RiverData> subRivers= new ArrayList<RiverData>(10);
	public Collection<RiverData> getSubRivers() {
		return subRivers;
	}
	public int getRiverId() {
		return riverId;
	}
	public void setRiverId(int riverId) {
		this.riverId = riverId;
	}
	public String getRiverName() {
		return riverName;
	}
	public void setRiverName(String riverName) {
		this.riverName = riverName;
	}
	public int getDestinationRiverId() {
		return destinationRiverId;
	}
	public void setDestinationRiverId(int destinationRiverId) {
		this.destinationRiverId = destinationRiverId;
	}
}

The question is, what annotations and how should I use them in this part of code:

    @OneToMany
    @JoinColumn(name="id_destination") // TODO: problem is here.
    private Collection<RiverData> subRivers= new ArrayList<RiverData>(10);

My idea was that the @JoinColumn would help me to select all rivers, which have the same id_destination, that equal to the id_river of this class.

PARTNERS