Jump to content

  • Log In with Google      Sign In   
  • Create Account

deathwearer

Member Since 25 Jul 2005
Offline Last Active Feb 18 2013 10:36 PM

Posts I've Made

In Topic: unique_ptr

12 December 2012 - 09:39 AM

Let's say I have three classes.

1. Player
2. GameScene
3. CameraController

The GameScene create the Player and the CameraController. Both are unique_ptr in the GameScene.

The CameraController needs the player to get it's position everytime its updates is called to center the camera on him. What I did was to receive a player pointer in the CameraController constructor and store it.

This scenario is simple enough to say, why don't you pass the pointer to the player each time you call your update method on CameraController. But for the sake of understanding the concept and good practices of unique_prt let's pretend there are other routine methods being call internally which require the player.

Should I have created a shared_ptr and pass the shared_ptr to the CameraController? So the ptr will be deleted when both the GameScene and CameraController get deleted?

In Topic: unique_ptr

11 December 2012 - 04:53 PM

1. You don't have to delete it
3. because then some other function can't get a copy of your pointer and then have an invalid pointer after your class is destructed

if i pass the unique_ptr.get() they have a copy if my ptr. they could also store that pointer in a class variable. Added question 4 at the topic.

In Topic: Java Scroller Game

11 December 2012 - 01:26 PM

Before going into threading (Which is a very delicate process) you better see how you can reduce processing time and memory allocation.

If you do the calculation of the same object more than once you might want to cache it somewhere.
Review container, if you don't need random access use forward iterator
What is called each loop. Do you call the only necessary stuff? Are you calling everything but should only call few things based on some conditions?
There are other optimization you can apply depending on game type etc. If there are no enemies in the screen, don't even check the bullets collision, stuff like that.

In Topic: Java Scroller Game

11 December 2012 - 12:57 PM

// HANDLE MANY ENEMIES - FAIL
ArrayList<Rectangle> enemiesBounds = new ArrayList<Rectangle>();
for (int i = 0; i < enemies.size(); ++i){
enemiesBounds.add(enemies.get(i).getBounds());
}
for (int i = 0; i > blasterShots.size(); ++i){

You wrote > when I think it should be <

Not sure if this cause your problem, but that would be a good bug to fix first Posted Image

In Topic: C# Custom Popup for DropDown.

11 December 2012 - 09:59 AM

Hey,

First are you using WinForm or WPF?

Also what is the .NET version?

PARTNERS