Skip to content

Commit

Permalink
BMSPlayer :refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
exch-bms2 committed Apr 11, 2018
1 parent 91ad222 commit cabb9bf
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 73 deletions.
12 changes: 11 additions & 1 deletion src/bms/player/beatoraja/BMSResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import bms.player.beatoraja.PlayerResource.PlayMode;
import bms.player.beatoraja.audio.AudioDriver;
import bms.player.beatoraja.play.bga.BGAProcessor;
import bms.player.beatoraja.select.bar.SongBar;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
Expand Down Expand Up @@ -36,6 +35,8 @@ public class BMSResource {
* BMSのBGAリソース
*/
private BGAProcessor bga;

private boolean bgaon;
/**
* BGA読み込みタスク
*/
Expand Down Expand Up @@ -108,10 +109,18 @@ public boolean setBMSFile(BMSModel model, final Path f, final Config config, Pla
return true;
}

public AudioDriver getAudioDriver() {
return audio;
}

public BGAProcessor getBGAProcessor() {
return bga;
}

public boolean isBGAOn() {
return bgaon;
}

public boolean mediaLoadFinished() {
if(!audioloaders.isEmpty() && audioloaders.getLast().isAlive()) {
return false;
Expand Down Expand Up @@ -182,6 +191,7 @@ public void run() {
try {
bga.abort();
bga.setModel(model);
bgaon = model != null;
} catch (Throwable e) {
Logger.getGlobal().severe(e.getClass().getName() + " : " + e.getMessage());
e.printStackTrace();
Expand Down
69 changes: 5 additions & 64 deletions src/bms/player/beatoraja/play/BMSPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public void render() {
// GET READY
case STATE_READY:
if (main.getNowTime(TIMER_READY) > skin.getPlaystart()) {
saveReplayHS();
replayConfig = lanerender.getPlayConfig().clone();
state = STATE_PLAY;
main.setMicroTimer(TIMER_PLAY, micronow - starttimeoffset * 1000);
main.setMicroTimer(TIMER_RHYTHM, micronow - starttimeoffset * 1000);
Expand Down Expand Up @@ -783,10 +783,6 @@ private void saveConfig() {
pc.setHidden(lanerender.getHiddenCover());
}

private void saveReplayHS() {
replayConfig = lanerender.getPlayConfig().clone();
}

public IRScoreData createScoreData() {
final PlayerResource resource = main.getPlayerResource();
final PlayerConfig config = resource.getPlayerConfig();
Expand Down Expand Up @@ -931,14 +927,6 @@ public int getNumberValue(int id) {
case NUMBER_TIMELEFT_SECOND:
return (Math.max((playtime - (int) (main.isTimerOn(TIMER_PLAY) ?
main.getNowTime(TIMER_PLAY) : 0) + 1000), 0) / 1000) % 60;
case NUMBER_LOADING_PROGRESS:
float value;
if(main.getPlayerResource().getConfig().getBga() == Config.BGA_ON
|| (main.getPlayerResource().getConfig().getBga() == Config.BGA_AUTO
&& (autoplay == PlayMode.AUTOPLAY || autoplay.isReplayMode()))) {
value = (main.getAudioProcessor().getProgress() + bga.getProgress()) / 2;
} else value = main.getAudioProcessor().getProgress();
return (int) (value * 100);
case NUMBER_GROOVEGAUGE:
return (int) gauge.getValue();
case NUMBER_GROOVEGAUGE_AFTERDOT:
Expand Down Expand Up @@ -970,42 +958,6 @@ public int getNumberValue(int id) {
return super.getNumberValue(id);
}

@Override
public float getSliderValue(int id) {
switch (id) {
case SLIDER_MUSIC_PROGRESS:
if (main.isTimerOn(TIMER_PLAY)) {
return Math.min((float) main.getNowTime(TIMER_PLAY) / playtime , 1);
}
return 0;
case SLIDER_LANECOVER:
case SLIDER_LANECOVER2:
final PlayConfig pc = lanerender.getPlayConfig();
if (pc.isEnablelanecover()) {
float lane = pc.getLanecover();
if (pc.isEnablelift()) {
lane = lane * (1 - pc.getLift());
}
return lane;
}
return 0;
case BARGRAPH_MUSIC_PROGRESS:
if (main.isTimerOn(TIMER_PLAY)) {
return Math.min((float) main.getNowTime(TIMER_PLAY) / playtime , 1);
}
return 0;
case BARGRAPH_LOAD_PROGRESS:
float value;
if(main.getPlayerResource().getConfig().getBga() == Config.BGA_ON
|| (main.getPlayerResource().getConfig().getBga() == Config.BGA_AUTO
&& (autoplay == PlayMode.AUTOPLAY || autoplay.isReplayMode()))) {
value = (main.getAudioProcessor().getProgress() + bga.getProgress()) / 2;
} else value = main.getAudioProcessor().getProgress();
return value;
}
return super.getSliderValue(id);
}

public boolean getBooleanValue(int id) {
switch (id) {
case OPTION_GAUGE_GROOVE:
Expand All @@ -1023,14 +975,6 @@ public boolean getBooleanValue(int id) {
return autoplay == PlayMode.PLAY || autoplay == PlayMode.PRACTICE;
case OPTION_REPLAY_PLAYING:
return autoplay.isReplayMode();
case OPTION_BGAON:
return main.getPlayerResource().getConfig().getBga() == Config.BGA_ON
|| (main.getPlayerResource().getConfig().getBga() == Config.BGA_AUTO
&& (autoplay == PlayMode.AUTOPLAY || autoplay.isReplayMode()));
case OPTION_BGAOFF:
return main.getPlayerResource().getConfig().getBga() == Config.BGA_OFF
|| (main.getPlayerResource().getConfig().getBga() == Config.BGA_AUTO
&& (autoplay == PlayMode.PLAY || autoplay == PlayMode.PRACTICE));
case OPTION_NOW_LOADING:
return state == STATE_PRELOAD;
case OPTION_LOADED:
Expand Down Expand Up @@ -1068,13 +1012,6 @@ public boolean getBooleanValue(int id) {
return super.getBooleanValue(id);
}

public int getImageIndex(int id) {
if (SkinPropertyMapper.isKeyJudgeValueId(id)) {
return judge.getJudge(id);
}
return super.getImageIndex(id);
}

public boolean isNoteEnd() {
return notes == main.getPlayerResource().getSongdata().getNotes();
}
Expand All @@ -1086,6 +1023,10 @@ public int getPastNotes() {
public void setPastNotes(int notes) {
this.notes = notes;
}

public int getPlaytime() {
return playtime;
}

public Mode getMode() {
return model.getMode();
Expand Down
74 changes: 66 additions & 8 deletions src/bms/player/beatoraja/skin/SkinPropertyMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import static bms.player.beatoraja.skin.SkinProperty.*;

import bms.model.Mode;
import bms.player.beatoraja.BMSResource;
import bms.player.beatoraja.Config;
import bms.player.beatoraja.MainState;
import bms.player.beatoraja.PlayConfig;
import bms.player.beatoraja.ScoreDataProperty;
import bms.player.beatoraja.PlayerResource.PlayMode;
import bms.player.beatoraja.play.BMSPlayer;
import bms.player.beatoraja.play.GrooveGauge.Gauge;
import bms.player.beatoraja.play.LaneRenderer;
Expand Down Expand Up @@ -89,11 +93,6 @@ public static int keyOffTimerId(int player, int key) {
}


public static boolean isKeyJudgeValueId(int valueId) {
return (valueId >= VALUE_JUDGE_1P_SCRATCH && valueId <= VALUE_JUDGE_2P_KEY9)
|| (valueId >= VALUE_JUDGE_1P_KEY10 && valueId <= VALUE_JUDGE_2P_KEY99);
}

public static int getKeyJudgeValuePlayer(int valueId) {
if (valueId >= VALUE_JUDGE_1P_SCRATCH && valueId <= VALUE_JUDGE_2P_KEY9) {
return (valueId - VALUE_JUDGE_1P_SCRATCH) / 10;
Expand Down Expand Up @@ -172,6 +171,15 @@ public static BooleanProperty getBooleanProperty(int optionid) {
// TODO 各Skinに分散するるべき?
BooleanProperty result = null;
final int id = Math.abs(optionid);

if(id == OPTION_BGAOFF || id == OPTION_BGAON) {
result = new DrawConditionProperty(DrawConditionProperty.TYPE_STATIC_WITHOUT_MUSICSELECT) {
@Override
public boolean get(MainState state) {
return id == OPTION_BGAON ? state.main.getPlayerResource().getBMSResource().isBGAOn() : !state.main.getPlayerResource().getBMSResource().isBGAOn();
}
};
}
if (id >= OPTION_7KEYSONG && id <= OPTION_9KEYSONG) {
final Mode[] modes = {Mode.BEAT_7K, Mode.BEAT_5K, Mode.BEAT_14K, Mode.BEAT_10K, Mode.POPN_9K};
result = new ModeDrawCondition(modes[id - OPTION_7KEYSONG]);
Expand Down Expand Up @@ -299,7 +307,15 @@ public static IntegerProperty getIntegerProperty(int optionid) {
return 0;
};
}


if(optionid == NUMBER_LOADING_PROGRESS) {
result = (state) -> {
final BMSResource resource = state.main.getPlayerResource().getBMSResource();
return (int) ((resource.isBGAOn() ? (resource.getBGAProcessor().getProgress() + resource.getAudioDriver().getProgress()) / 2 :
resource.getAudioDriver().getProgress()) * 100);
};
}

return result;
}

Expand All @@ -319,6 +335,16 @@ public static IntegerProperty getImageIndexProperty(int optionid) {
result = (state) -> (state.main.getPlayerResource().getPlayerConfig().getDoubleoption());
}

if((optionid >= VALUE_JUDGE_1P_SCRATCH && optionid <= VALUE_JUDGE_2P_KEY9)
|| (optionid >= VALUE_JUDGE_1P_KEY10 && optionid <= VALUE_JUDGE_2P_KEY99)) {
result = (state) -> {
if(state instanceof BMSPlayer) {
return ((BMSPlayer) state).getJudgeManager().getJudge(optionid);
}
return 0;
};
}

return result;
}

Expand All @@ -344,8 +370,40 @@ public static FloatProperty getFloatProperty(int optionid) {
}
if(optionid == BARGRAPH_TARGETSCORERATE) {
result = (state) -> (state.getScoreDataProperty().getRivalScoreRate());
}

}
if(optionid == BARGRAPH_LOAD_PROGRESS) {
result = (state) -> {
final BMSResource resource = state.main.getPlayerResource().getBMSResource();
return resource.isBGAOn() ? (resource.getBGAProcessor().getProgress() + resource.getAudioDriver().getProgress()) / 2 :
resource.getAudioDriver().getProgress();
};
}
if(optionid == SLIDER_MUSIC_PROGRESS || optionid == BARGRAPH_MUSIC_PROGRESS) {
result = (state) -> {
if(state instanceof BMSPlayer) {
if (state.main.isTimerOn(TIMER_PLAY)) {
return Math.min((float) state.main.getNowTime(TIMER_PLAY) / ((BMSPlayer)state).getPlaytime() , 1);
}
}
return 0;
};
}
if(optionid == SLIDER_LANECOVER || optionid == SLIDER_LANECOVER2) {
result = (state) -> {
if(state instanceof BMSPlayer) {
final PlayConfig pc = ((BMSPlayer) state).getLanerender().getPlayConfig();
if (pc.isEnablelanecover()) {
float lane = pc.getLanecover();
if (pc.isEnablelift()) {
lane = lane * (1 - pc.getLift());
}
return lane;
}
}
return 0;
};
}

return result;
}

Expand Down

0 comments on commit cabb9bf

Please sign in to comment.