Skip to content

Commit

Permalink
general minor fixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosfox committed May 31, 2012
1 parent 8a5193a commit 237fd2b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 55 deletions.
11 changes: 11 additions & 0 deletions src/org/open2jam/gui/ChartListTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,22 @@ public ChartList getRow(int row)
return items.get(row);
}

@Override
public int getRowCount() {
return items.size();
}

@Override
public int getColumnCount() {
return col_names.length;
}

@Override
public String getColumnName(int columnIndex) {
return col_names[columnIndex];
}

@Override
public Class<?> getColumnClass(int columnIndex) {
switch(columnIndex)
{
Expand All @@ -79,12 +83,16 @@ public Class<?> getColumnClass(int columnIndex) {
return Object.class;
}

@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {

Chart c;
if(items.size() <= rowIndex)return null;
if(items.get(rowIndex).isEmpty()) return null;
if(items.get(rowIndex).size()-1 < rank)
c = items.get(rowIndex).get(0);
Expand All @@ -103,14 +111,17 @@ public Object getValueAt(int rowIndex, int columnIndex) {
return null;
}

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
throw new UnsupportedOperationException("Can't do that cowboy");
}

@Override
public void addTableModelListener(TableModelListener l) {
listeners.add(l);
}

@Override
public void removeTableModelListener(TableModelListener l) {
listeners.remove(l);
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/open2jam/gui/parts/MusicSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class MusicSelection extends javax.swing.JPanel

private class RenderThread extends Thread {

Container c;
Render r;
final Container c;
final Render r;
public RenderThread(Container c, Render r) {
this.c = c;
this.r = r;
Expand Down
12 changes: 5 additions & 7 deletions src/org/open2jam/parser/Chart.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.open2jam.parser;

import java.io.File;
import java.util.List;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.imageio.ImageIO;
Expand Down Expand Up @@ -53,6 +52,7 @@ public abstract class Chart implements Comparable<Chart>, java.io.Serializable
/** this should return the list of events from this chart at this rank */
public abstract List<Event> getEvents();

@Override
public int compareTo(Chart c)
{
return getLevel() - c.getLevel();
Expand All @@ -64,10 +64,8 @@ public BufferedImage getNoImage()
if(u == null) return null;

try {
return ImageIO.read(new File(u.toURI()));
} catch (URISyntaxException ex) {
Logger.global.log(Level.WARNING, "Someone deleted or renamed my no_image image file :_ {0}", ex.getMessage());
} catch (IOException ex) {
return ImageIO.read(u);
} catch (IOException ex) {
Logger.global.log(Level.WARNING, "Someone deleted or renamed my no_image image file :_ {0}", ex.getMessage());
}
return null;
Expand Down
61 changes: 20 additions & 41 deletions src/org/open2jam/render/Render.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,22 @@
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
import java.util.logging.Level;
import org.open2jam.util.Logger;
import javax.swing.JOptionPane;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;

import org.lwjgl.opengl.DisplayMode;
import org.open2jam.Config;
import org.open2jam.GameOptions;
import org.open2jam.parser.Event;
import org.open2jam.parser.Chart;
import org.open2jam.render.entities.BarEntity;
import org.open2jam.render.entities.ComboCounterEntity;
import org.open2jam.render.entities.CompositeEntity;
import org.open2jam.render.entities.Entity;
import org.open2jam.render.entities.LongNoteEntity;
import org.open2jam.render.entities.MeasureEntity;
import org.open2jam.render.entities.NoteEntity;
import org.open2jam.render.entities.NumberEntity;
import org.open2jam.render.entities.SampleEntity;
import org.open2jam.render.entities.TimeEntity;
import org.open2jam.parser.Event;
import org.open2jam.render.entities.*;
import org.open2jam.render.lwjgl.SoundManager;
import org.open2jam.render.lwjgl.TrueTypeFont;
import org.open2jam.util.Interval;
import org.open2jam.util.IntervalTree;
import org.open2jam.util.Logger;
import org.open2jam.util.SystemTimer;

/**
Expand Down Expand Up @@ -240,17 +223,18 @@ public abstract class Render implements GameWindowCallback
AUTOSOUND = opt.getAutosound();

//TODO Should get values from gameoptions, but i'm lazy as hell
if(opt.getAutoplay())
if(opt.getAutoplay())
{
for(Event.Channel c : Event.Channel.values())
{
if(c.toString().startsWith(("NOTE_")))
c.enableAutoplay();
if(c.toString().startsWith(("NOTE_"))) c.enableAutoplay();
}

// Event.Channel.NOTE_4.enableAutoplay();
// Event.Channel.NOTE_1.enableAutoplay();
}
} else {
for(Event.Channel c : Event.Channel.values())
{
if(c.toString().startsWith(("NOTE_"))) c.disableAutoplay();
}
}

window.setDisplay(dm,opt.getVsync(),opt.getFullScreen(),opt.getBilinear());
}
Expand Down Expand Up @@ -325,7 +309,7 @@ public void initialise()
// reference to long notes being holded
longnote_holded = new EnumMap<Event.Channel,LongNoteEntity>(Event.Channel.class);

longflare = new EnumMap<Event.Channel, Entity> (Event.Channel.class);
longflare = new EnumMap<Event.Channel, Entity> (Event.Channel.class);

last_sound = new EnumMap<Event.Channel,Event.SoundSample>(Event.Channel.class);

Expand Down Expand Up @@ -959,10 +943,9 @@ private List<Event> construct_velocity_tree(List<Event> list)
*/
double velocity_integral(double t0, double t1)
{
boolean negative = false;
if(t0 > t1){
final boolean negative = t0 > t1;
if(negative){
double tmp = t1;t1 = t0;t0 = tmp; // swap
negative = true;
}
List<Interval<Double,Double>> list = velocity_tree.getIntervals(t0, t1);
double integral = 0;
Expand Down Expand Up @@ -1083,9 +1066,9 @@ void channelRandom(Iterator<Event> buffer)

Collections.shuffle(channelSwap);

EnumMap<Event.Channel, Event.Channel> lnMap = new EnumMap<Event.Channel, Event.Channel>(Event.Channel.class);
EnumMap<Event.Channel, Event.Channel> lnMap = new EnumMap<Event.Channel, Event.Channel>(Event.Channel.class);

int last_measure = -1;
int last_measure = -1;
while(buffer.hasNext())
{
Event e = buffer.next();
Expand Down Expand Up @@ -1149,20 +1132,16 @@ else if(e.getFlag() == Event.Flag.NONE)

private void visibility(GameOptions.VisibilityMod value)
{
int height = 0;
int width = 0;

Sprite rec = null;
// We will make a new entity with the masking rectangle for each note lane
// because we can't know for sure where the notes will be,
// meaning that they may not be together
for(Event.Channel ev : Event.Channel.values())
{
if(ev.toString().startsWith("NOTE_") && skin.getEntityMap().get(ev.toString()) != null)
{
height = (int)Math.round(getViewport());
width = (int)Math.round(skin.getEntityMap().get(ev.toString()).getWidth());
rec = ResourceFactory.get().doRectangle(width, height, value);
int height = (int)Math.round(getViewport());
int width = (int)Math.round(skin.getEntityMap().get(ev.toString()).getWidth());
Sprite rec = ResourceFactory.get().doRectangle(width, height, value);
visibility_entity.getEntityList().add(new Entity(rec, skin.getEntityMap().get(ev.toString()).getX(), 0));
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/org/open2jam/render/entities/NumberEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ public void draw()
String numberString = String.valueOf(number);
if(numberString.length() < show_digits)
{
String zeros = "";
for(int i = 1; i<show_digits;i++) zeros += "0";
numberString = zeros+numberString;
StringBuilder zeros = new StringBuilder(show_digits);
for(int i = numberString.length(); i<show_digits;i++)
zeros.append('0');
numberString = zeros.append(numberString).toString();
}
double tx = x;
char[] chars = numberString.toCharArray();
for(int j=chars.length-1;j>=0;j--)
{
int i = Integer.parseInt(chars[j]+"");
int i = chars[j] - '0';
tx -= entity_list.get(i).getWidth();
entity_list.get(i).setPos(tx,y);
entity_list.get(i).draw();
Expand Down
4 changes: 3 additions & 1 deletion src/org/open2jam/render/lwjgl/LWJGLSprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ public void setAlpha(float alpha)
*/
void draw(float px, float py, float sx, float sy)
{
if(texture == null)return;

// store the current model matrix
GL11.glPushMatrix();

// bind to the appropriate texture for this sprite
if(texture!=null)texture.bind();
texture.bind();

// translate to the right location and prepare to draw
GL11.glTranslatef(px, py, 0);
Expand Down

0 comments on commit 237fd2b

Please sign in to comment.