Skip to content

Commit

Permalink
Merge branch 'rewrite/master' into input-offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 committed Feb 10, 2024
2 parents aeddcee + 902eb3a commit d903edc
Show file tree
Hide file tree
Showing 63 changed files with 4,661 additions and 1,260 deletions.
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
"target": "windows",
"args": ["-debug", "-DSONG=bopeebo -DDIFFICULTY=normal"]
},
{
"label": "Windows / Debug (Conversation Test)",
"target": "windows",
"args": ["-debug", "-DDIALOGUE"]
},
{
"label": "Windows / Debug (Straight to Chart Editor)",
"target": "windows",
Expand All @@ -125,6 +130,11 @@
"target": "windows",
"args": ["-debug", "-DLATENCY"]
},
{
"label": "Windows / Debug (Waveform Test)",
"target": "windows",
"args": ["-debug", "-DWAVEFORM"]
},
{
"label": "HTML5 / Debug",
"target": "html5",
Expand Down
7 changes: 4 additions & 3 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<library name="week7" preload="false" />
<library name="weekend1" preload="false" />
</section>
<library name="art" preload="false" />
<assets path="assets/songs" library="songs" exclude="*.fla|*.ogg" if="web" />
<assets path="assets/songs" library="songs" exclude="*.fla|*.mp3" unless="web" />
<assets path="assets/shared" library="shared" exclude="*.fla|*.ogg" if="web" />
Expand Down Expand Up @@ -82,14 +83,15 @@
If we can exclude the `mods` folder from the manifest, we can re-enable this line.
<assets path='example_mods' rename='mods' embed='false' exclude="*.md" />
-->
<assets path="art/readme.txt" rename="do NOT readme.txt" />
<assets path="CHANGELOG.md" rename="changelog.txt" />
<assets path="art/readme.txt" rename="do NOT readme.txt" library="art"/>
<assets path="CHANGELOG.md" rename="changelog.txt" library="art"/>
<!-- NOTE FOR FUTURE SELF SINCE FONTS ARE ALWAYS FUCKY
TO FIX ONE OF THEM, I CONVERTED IT TO OTF. DUNNO IF YOU NEED TO
THEN UHHH I USED THE NAME OF THE FONT WITH SETFORMAT() ON THE TEXT!!!
NOT USING A DIRECT THING TO THE ASSET!!!
-->
<assets path="assets/fonts" embed="true" />

<!-- _______________________________ Libraries ______________________________ -->
<haxelib name="lime" /> <!-- Game engine backend -->
<haxelib name="openfl" /> <!-- Game engine backend -->
Expand All @@ -108,7 +110,6 @@
<haxelib name="hxCodec" /> <!-- Video playback -->

<haxelib name="json2object" /> <!-- JSON parsing -->
<haxelib name="tink_json" /> <!-- JSON parsing (DEPRECATED) -->
<haxelib name="thx.semver" /> <!-- Version string handling -->

<haxelib name="hmm" /> <!-- Read library version data at compile time so it can be baked into logs -->
Expand Down
2 changes: 1 addition & 1 deletion assets
11 changes: 3 additions & 8 deletions hmm.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"name": "flixel-addons",
"type": "git",
"dir": null,
"ref": "fd3aecdeb5635fa0428dffee204fc78fc26b5885",
"ref": "a523c3b56622f0640933944171efed46929e360e",
"url": "https://github.com/FunkinCrew/flixel-addons"
},
{
Expand Down Expand Up @@ -54,7 +54,7 @@
"name": "haxeui-core",
"type": "git",
"dir": null,
"ref": "a551159",
"ref": "8a7846b",
"url": "https://github.com/haxeui/haxeui-core"
},
{
Expand Down Expand Up @@ -149,18 +149,13 @@
"name": "polymod",
"type": "git",
"dir": null,
"ref": "cb11a95d0159271eb3587428cf4b9602e46dc469",
"ref": "6cec79e4f322fbb262170594ed67ab72b4714810",
"url": "https://github.com/larsiusprime/polymod"
},
{
"name": "thx.semver",
"type": "haxelib",
"version": "0.2.2"
},
{
"name": "tink_json",
"type": "haxelib",
"version": "0.11.0"
}
]
}
2 changes: 2 additions & 0 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Main extends Sprite

public static function main():Void
{
haxe.Log.trace = funkin.util.logging.AnsiTrace.trace;
funkin.util.logging.AnsiTrace.traceBF();
Lib.current.addChild(new Main());
}

Expand Down
31 changes: 21 additions & 10 deletions source/funkin/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import funkin.data.level.LevelRegistry;
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.data.event.SongEventRegistry;
import funkin.data.stage.StageRegistry;
import funkin.play.cutscene.dialogue.ConversationDataParser;
import funkin.play.cutscene.dialogue.DialogueBoxDataParser;
import funkin.play.cutscene.dialogue.SpeakerDataParser;
import funkin.data.dialogue.ConversationRegistry;
import funkin.data.dialogue.DialogueBoxRegistry;
import funkin.data.dialogue.SpeakerRegistry;
import funkin.data.song.SongRegistry;
import funkin.play.character.CharacterData.CharacterDataParser;
import funkin.modding.module.ModuleHandler;
Expand Down Expand Up @@ -208,22 +208,29 @@ class InitState extends FlxState
// GAME DATA PARSING
//

// NOTE: Registries and data parsers must be imported and not referenced with fully qualified names,
// NOTE: Registries must be imported and not referenced with fully qualified names,
// to ensure build macros work properly.
trace('Parsing game data...');
var perfStart = haxe.Timer.stamp();
SongEventRegistry.loadEventCache(); // SongEventRegistry is structured differently so it's not a BaseRegistry.
SongRegistry.instance.loadEntries();
LevelRegistry.instance.loadEntries();
NoteStyleRegistry.instance.loadEntries();
SongEventRegistry.loadEventCache();
ConversationDataParser.loadConversationCache();
DialogueBoxDataParser.loadDialogueBoxCache();
SpeakerDataParser.loadSpeakerCache();
ConversationRegistry.instance.loadEntries();
DialogueBoxRegistry.instance.loadEntries();
SpeakerRegistry.instance.loadEntries();
StageRegistry.instance.loadEntries();
CharacterDataParser.loadCharacterCache();

// TODO: CharacterDataParser doesn't use json2object, so it's way slower than the other parsers.
CharacterDataParser.loadCharacterCache(); // TODO: Migrate characters to BaseRegistry.

ModuleHandler.buildModuleCallbacks();
ModuleHandler.loadModuleCache();

ModuleHandler.callOnCreate();

var perfEnd = haxe.Timer.stamp();

trace('Parsing game data took ${Math.floor((perfEnd - perfStart) * 1000)}ms.');
}

/**
Expand All @@ -241,8 +248,12 @@ class InitState extends FlxState
startLevel(defineLevel(), defineDifficulty());
#elseif FREEPLAY // -DFREEPLAY
FlxG.switchState(new FreeplayState());
#elseif DIALOGUE // -DDIALOGUE
FlxG.switchState(new funkin.ui.debug.dialogue.ConversationDebugState());
#elseif ANIMATE // -DANIMATE
FlxG.switchState(new funkin.ui.debug.anim.FlxAnimateTest());
#elseif WAVEFORM // -DWAVEFORM
FlxG.switchState(new funkin.ui.debug.WaveformTestState());
#elseif CHARTING // -DCHARTING
FlxG.switchState(new funkin.ui.debug.charting.ChartEditorState());
#elseif STAGEBUILD // -DSTAGEBUILD
Expand Down
107 changes: 106 additions & 1 deletion source/funkin/audio/FunkinSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import flash.utils.ByteArray;
import flixel.sound.FlxSound;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.system.FlxAssets.FlxSoundAsset;
import funkin.util.tools.ICloneable;
import funkin.audio.waveform.WaveformData;
import funkin.audio.waveform.WaveformDataParser;
import flixel.math.FlxMath;
import openfl.Assets;
#if (openfl >= "8.0.0")
import openfl.utils.AssetType;
Expand All @@ -17,17 +21,63 @@ import openfl.utils.AssetType;
* - Delayed playback via negative song position.
*/
@:nullSafety
class FunkinSound extends FlxSound
class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
{
static final MAX_VOLUME:Float = 2.0;

static var cache(default, null):FlxTypedGroup<FunkinSound> = new FlxTypedGroup<FunkinSound>();

public var muted(default, set):Bool = false;

function set_muted(value:Bool):Bool
{
if (value == muted) return value;
muted = value;
updateTransform();
return value;
}

override function set_volume(value:Float):Float
{
// Uncap the volume.
fixMaxVolume();
_volume = FlxMath.bound(value, 0.0, MAX_VOLUME);
updateTransform();
return _volume;
}

public var paused(get, never):Bool;

function get_paused():Bool
{
return this._paused;
}

public var isPlaying(get, never):Bool;

function get_isPlaying():Bool
{
return this.playing || this._shouldPlay;
}

/**
* Waveform data for this sound.
* This is lazily loaded, so it will be built the first time it is accessed.
*/
public var waveformData(get, never):WaveformData;

var _waveformData:Null<WaveformData> = null;

function get_waveformData():WaveformData
{
if (_waveformData == null)
{
_waveformData = WaveformDataParser.interpretFlxSound(this);
if (_waveformData == null) throw 'Could not interpret waveform data!';
}
return _waveformData;
}

/**
* Are we in a state where the song should play but time is negative?
*/
Expand Down Expand Up @@ -63,6 +113,30 @@ class FunkinSound extends FlxSound
}
}

public function togglePlayback():FunkinSound
{
if (playing)
{
pause();
}
else
{
resume();
}
return this;
}

function fixMaxVolume():Void
{
#if lime_openal
// This code is pretty fragile, it reaches through 5 layers of private access.
@:privateAccess
var handle = this?._channel?.__source?.__backend?.handle;
if (handle == null) return;
lime.media.openal.AL.sourcef(handle, lime.media.openal.AL.MAX_GAIN, MAX_VOLUME);
#end
}

public override function play(forceRestart:Bool = false, startTime:Float = 0, ?endTime:Float):FunkinSound
{
if (!exists) return this;
Expand Down Expand Up @@ -140,6 +214,37 @@ class FunkinSound extends FlxSound
return this;
}

/**
* Call after adjusting the volume to update the sound channel's settings.
*/
@:allow(flixel.sound.FlxSoundGroup)
override function updateTransform():Void
{
_transform.volume = #if FLX_SOUND_SYSTEM ((FlxG.sound.muted || this.muted) ? 0 : 1) * FlxG.sound.volume * #end
(group != null ? group.volume : 1) * _volume * _volumeAdjust;

if (_channel != null) _channel.soundTransform = _transform;
}

public function clone():FunkinSound
{
var sound:FunkinSound = new FunkinSound();

// Clone the sound by creating one with the same data buffer.
// Reusing the `Sound` object directly causes issues with playback.
@:privateAccess
sound._sound = openfl.media.Sound.fromAudioBuffer(this._sound.__buffer);

// Call init to ensure the FlxSound is properly initialized.
sound.init(this.looped, this.autoDestroy, this.onComplete);

// Oh yeah, the waveform data is the same too!
@:privateAccess
sound._waveformData = this._waveformData;

return sound;
}

/**
* Creates a new `FunkinSound` object.
*
Expand Down
Loading

0 comments on commit d903edc

Please sign in to comment.