Worrying performace issues.
in
Programming Questions
•
10 months ago
Been doing some more messing around with processing and, whether it's my laptop or just linux, processing apps consume a lot of ram and run slowly. While my laptop isn't the fastest machine around a simple app should not be using up 100mb of ram. Also the opengl renderer seems rather slow. Most likely this is me coding unoptimized pieces of code. Lastly what kind of size (in ram) is a pshape (yes this'll change on different shapes). I'll upload a sample app i made to see what you think of it.
- void setup()
{
frameRate(30);
smooth();
size(displayWidth, displayHeight, OPENGL);
SizeDone = true;
Targets[0] = new Target(0, 0, displayWidth, displayHeight, true, SizeDone, true);
Targets[0].GraphicsInit();
}
void draw()
{
background(255);
Targets[0].Draw();
}
void mousePressed()
{
if (mouseButton == LEFT) {
Targets[0].Shot();
}
else if (mouseButton == RIGHT)
{
}
}
- boolean SizeDone = false;
Target[] Targets = new Target[1];
String Mode = "Target";
int ModeNumber = 0;
- class Shot
{
public PShape Bullet;
public PShape Averagess;
private double TargetScale;
public ArrayList Vectors = new ArrayList();
public Shot(double Targetscale)
{
TargetScale = Targetscale*0.04869565217;
Setup();
}
public void Setup()
{
float Size = (float)TargetScale;
Bullet = createShape(ELLIPSE, 0, 0, Size, Size);
Averagess = createShape(RECT, Size/4, Size/4, Size/2, Size/2);
Averagess.fill(255, 60);
Bullet.fill(0, 60);
Bullet.noStroke();
}
public void AddShot(Vector2 shot)
{
shot.X -= TargetScale/2;
shot.Y -= TargetScale/2;
Vectors.add(shot);
}
public void SaveShots()
{
}
public void Draw()
{
// Iterator itr = Vectors.iterator();
// while (itr.hasNext ()) {
// //Vector2 element = itr.next();
// object xz = itr.next();
Vector2 Average = new Vector2(0, 0);
for (int i = Vectors.size()-1; i >= 0; i--) {
Vector2 vectors = (Vector2) Vectors.get(i);
Average.X += vectors.X;
Average.Y += vectors.Y;
}
Average.X = Average.X/Vectors.size();
Average.Y = Average.Y/Vectors.size();
pushMatrix();
translate(Average.X,Average.Y);
shape(Averagess);
popMatrix();
for (int i = Vectors.size()-1; i >= 0; i--) {
// An ArrayList doesn't know what it is storing,
// so we have to cast the object coming out.
Vector2 vectors = (Vector2) Vectors.get(i);
pushMatrix();
translate(vectors.X, vectors.Y);
shape(Bullet);
popMatrix();
}
}
}
class Vector2
{
public float X;
public float Y;
public Vector2(float eX, float eY)
{
X = eX;
Y = eY;
}
}
- class Target
{
private PShape Targets;
private int X;
private int Y;
private int SizeX;
private int SizeY;
private boolean InnerRing;
public Shot Shots;
public Target(int Xc, int Yc, int SizeXc, int SizeYc, boolean Ring, boolean SizeDone, boolean RetainSize)
{
X = Xc;
Y = Yc;
SizeX = SizeXc;
SizeY = SizeYc;
if (RetainSize == true)
{
if (SizeX > SizeY)
{
SizeX = SizeY;
}
else
{
SizeY = SizeX;
}
}
InnerRing = Ring;
if (SizeDone == true)
{
GraphicsInit();
}
}
public void GraphicsInit()
{
Shots = new Shot(SizeX);
Targets = createShape(GROUP);
PShape Ring1 = createShape(ELLIPSE, 0, 0, SizeX, SizeY);
PShape Ring2 = createShape(ELLIPSE,
(0.60869565217/2)*SizeX, (0.60869565217/2)*SizeY,
0.39130434782*SizeX, 0.39130434782*SizeY);
PShape Ring3 = createShape(ELLIPSE,
(0.35)*SizeX, (0.35)*SizeY,
0.3*SizeX, 0.3*SizeY);
Ring1.fill(200);
Ring1.noStroke();
Ring2.fill(255);
Ring2.noStroke();
Ring3.fill(200);
Ring3.noStroke();
Targets.addChild(Ring1);
Targets.addChild(Ring2);
Targets.addChild(Ring3);
}
public void Shot()
{
Shots.AddShot(new Vector2(mouseX, mouseY));
}
public void Draw()
{
shape(Targets);
Shots.Draw();
}
}
If you can give me any help with these issues i'd be pretty happy.
1