Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
645 changes: 190 additions & 455 deletions Encore/src/assets.cpp

Large diffs are not rendered by default.

518 changes: 302 additions & 216 deletions Encore/src/assets.h

Large diffs are not rendered by default.

90 changes: 65 additions & 25 deletions Encore/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#include "util/discord.h"
#include "util/enclog.h"
#include "gameplay/enctime.h"


#include <cassert>

#include "settings/keybinds.h"
#include "song/cacheload.h"
#define assertm(exp, msg) assert((void(msg), exp))

#define RAYGUI_IMPLEMENTATION
Expand Down Expand Up @@ -88,6 +91,22 @@ std::string commitHash = GIT_COMMIT_HASH;
int minWidth = 640;
int minHeight = 480;

void DrawLoadingScreen(unsigned char alpha, float progress) {
Texture icon = ASSET(faviconTex);
float fade = (1.0 - (alpha/255.0));
fade *= fade;
unsigned char quadAlpha = 255*(1.0-fade);
float scale = (GetScreenHeight() / 1080.0f) * 0.3;
float iconScale = scale + fade * 0.5;
int iconSize = (icon.height * iconScale)/2; // Dividing by 2 for centering
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), {0, 0, 0, quadAlpha});

Vector2 screenCenter = {GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
DrawRing(screenCenter, scale*300.0f, scale*320.0f, -90, 360-90, 64, {255, 255, 255, (unsigned char)(alpha/3)});
DrawRing(screenCenter, scale*300.0f, scale*320.0f, -90, 360*progress-90, 64, {255, 255, 255, alpha});
DrawTextureEx(icon, {GetScreenWidth()/2.0f-iconSize, GetScreenHeight()/2.0f-iconSize}, 0, iconScale, {255, 255, 255, alpha});
}

int main(int argc, char *argv[]) {
TheGameRPC.Initialize();
SetTraceLogCallback(Encore::EncoreLog);
Expand All @@ -97,7 +116,6 @@ int main(int argc, char *argv[]) {
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
glfwWindowHint(GLFW_SAMPLES, 4);

SetWindowState(FLAG_MSAA_4X_HINT);
bool windowToggle = true;
ArgumentList::InitArguments(argc, argv);

Expand Down Expand Up @@ -135,29 +153,29 @@ int main(int argc, char *argv[]) {
CFRelease(bundle);
}
#endif

TheSettingsInitializer.InitSettings(directory);
CacheLoad::StartLoad();
ThePlayerManager.SetPlayerListSaveFileLocation(directory / "players.json");

ThePlayerManager.LoadPlayerList();

if (TheGameSettings.VerticalSync) {
SetConfigFlags(FLAG_VSYNC_HINT);
}
Encore::EncoreLog(LOG_INFO, TextFormat("Vertical sync: %d", vsyncArg));
InitWindow(800, 600, "Encore");
if (!TheGameSettings.Fullscreen) {
InitWindow(
GetMonitorWidth(GetCurrentMonitor()) * 0.75f,
GetMonitorHeight(GetCurrentMonitor()) * 0.75f,
"Encore"
);
SET_WINDOW_WINDOWED();
int x, y, width, height;
glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &x, &y, &width, &height);
Encore::EncoreLog(LOG_INFO, TextFormat("Workarea of monitor %s: %i %i %i %i", glfwGetMonitorName(glfwGetPrimaryMonitor()), x, y, width, height));
int windowWidth = width * 0.75;
int windowHeight = height * 0.75;
SetWindowPosition(width/2 - windowWidth/2 + x, height/2 - windowHeight/2 + y);
SetWindowSize(windowWidth, windowHeight);
ClearWindowState(FLAG_WINDOW_UNDECORATED);
MaximizeWindow();
} else {
InitWindow(
GetMonitorWidth(GetCurrentMonitor()),
GetMonitorHeight(GetCurrentMonitor()),
"Encore"
);
SetWindowSize(GetMonitorWidth(0), GetMonitorHeight(0));
SET_WINDOW_FULLSCREEN_BORDERLESS();
}
bool AudioInitSuccessful = TheAudioManager.Init();
Expand All @@ -172,11 +190,19 @@ int main(int argc, char *argv[]) {
SETDEFAULTSTYLE();

SetRandomSeed(std::chrono::system_clock::now().time_since_epoch().count());
assets.FirstAssets();
SetWindowIcon(assets.icon);
GuiSetFont(assets.rubik);
assets.LoadAssets();
TheMenuManager.currentScreen = CACHE_LOADING_SCREEN;
initialSet.StartLoad();
TheAssets.AddRingsAndInstruments();
mainMenuSet.StartLoad();
AssetSet({ASSETPTR(favicon), ASSETPTR(faviconTex)}).BlockUntilLoaded();
SetWindowIcon(LoadImageFromMemory(".png", ASSET(favicon), ASSET(favicon).GetFileSize()));
if (!CacheLoad::finished) {
TheMenuManager.currentScreen = CACHE_LOADING_SCREEN;
} else {
TheMenuManager.currentScreen = MAIN_MENU;
}




if (TheGameSettings.Framerate > 0)
Encore::EncoreLog(
Expand All @@ -186,13 +212,12 @@ int main(int argc, char *argv[]) {
Encore::EncoreLog(LOG_INFO, TextFormat("Unlocked framerate."));
TheFrameManager.removeFPSLimit = true;
}

// audioManager.loadSample("Assets/highway/clap.mp3", "clap");
while (!WindowShouldClose()) {
u.calcUnits();
double curTime = GetTime();
float bgTime = curTime / 5.0f;
SetShaderValue(assets.bgShader, assets.bgTimeLoc, &bgTime, SHADER_UNIFORM_FLOAT);
SetShaderValue(ASSET(bgShader), ASSET(bgShader).GetUniformLoc("time"), &bgTime, SHADER_UNIFORM_FLOAT);
if (IsKeyPressed(KEY_F11)
|| (IsKeyPressed(KEY_LEFT_ALT) && IsKeyPressed(KEY_ENTER))) {
TheGameSettings.Fullscreen = !TheGameSettings.Fullscreen;
Expand All @@ -217,12 +242,27 @@ int main(int argc, char *argv[]) {

BeginDrawing();
ClearBackground(DARKGRAY);

if (TheMenuManager.onNewMenu) {
TheMenuManager.LoadMenu();
static bool showLoading = true;
if (showLoading && !initialSet.PollLoaded(true)) {
DrawLoadingScreen(255, initialSet.GetProgress());
} else {
static float loadingScreenFade = 1.0f;
showLoading = false;
if (TheMenuManager.onNewMenu) {
TheMenuManager.LoadMenu();
}
TheGameRPC.Update();
TheMenuManager.DrawMenu();
if (loadingScreenFade > 0) {
DrawLoadingScreen(255*loadingScreenFade, 1);
float frameTime = GetFrameTime();
// Cap the frame time here so the fade animation doesn't get skipped by the stutter caused by loading the song preview
if (frameTime > 0.032) {
frameTime = 0.032;
}
loadingScreenFade -= frameTime*5.0f;
}
}
TheGameRPC.Update();
TheMenuManager.DrawMenu();
EndDrawing();

TheFrameManager.WaitForFrame();
Expand Down
12 changes: 6 additions & 6 deletions Encore/src/menus/ReadyUpMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ void ReadyUpMenu::Draw() {
|| player.Instrument == PlasticBass) {
isBassOrVocal = 1;
}
SetShaderValue(
assets.odMultShader,
assets.isBassOrVocalLoc,
&isBassOrVocal,
SHADER_UNIFORM_INT
);
// SetShaderValue(
// assets.odMultShader,
// assets.isBassOrVocalLoc,
// &isBassOrVocal,
// SHADER_UNIFORM_INT
// );
}
GuiSetStyle(BUTTON, TEXT_COLOR_NORMAL, 0xcbcbcbFF);
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
Expand Down
24 changes: 19 additions & 5 deletions Encore/src/menus/SongSelectMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void SongSelectMenu::Draw() {
);
} else if (!TheSongList.listMenuEntries[i].hiddenEntry) {
bool isCurSong = TheSongList.curSong && i == TheSongList.curSong->songListPos - 1;
Font &artistFont = isCurSong ? assets.josefinSansItalic : assets.josefinSansItalic;
Font artistFont = assets.josefinSansItalic;
Song &songi = TheSongList.songs[TheSongList.listMenuEntries[i].songListID];
int songID = TheSongList.listMenuEntries[i].songListID;

Expand Down Expand Up @@ -569,11 +569,25 @@ void SongSelectMenu::Draw() {
float IconLeftPos = (float)(u.RightSide - AlbumHeight) + IconWidth * ResetToLeftPos;
Rectangle Placement = { IconLeftPos, BoxTopPos, IconWidth, IconWidth };
Color TintColor = WHITE;
if (SongToDisplayInfo.parts[i] && SongToDisplayInfo.parts[i]->diff == -1) TintColor = DARKGRAY;
DrawTexturePro(assets.InstIcons[asdasd], { 0, 0, (float)assets.InstIcons[asdasd].width, (float)assets.InstIcons[asdasd].height }, Placement, { 0, 0 }, 0, TintColor);
int diffNumber = SongToDisplayInfo.parts[i]->diff;
if (SongToDisplayInfo.parts[i] && diffNumber == -1) TintColor = DARKGRAY;
auto instIcon = assets.InstIcons[asdasd];
DrawTexturePro(*instIcon, { 0, 0, (float)instIcon->width, (float)instIcon->height }, Placement, { 0, 0 }, 0, TintColor);
DrawTexturePro(assets.BaseRingTexture, { 0, 0, (float)assets.BaseRingTexture.width, (float)assets.BaseRingTexture.height }, Placement, { 0, 0 }, 0, ColorBrightness(WHITE, 2));
if (SongToDisplayInfo.parts[i] && SongToDisplayInfo.parts[i]->diff > 0)
DrawTexturePro(assets.YargRings[SongToDisplayInfo.parts[i]->diff - 1], { 0, 0, (float)assets.YargRings[SongToDisplayInfo.parts[i]->diff - 1].width, (float)assets.YargRings[SongToDisplayInfo.parts[i]->diff - 1].height }, Placement, { 0, 0 }, 0, WHITE);
if (SongToDisplayInfo.parts[i] && diffNumber > 0) {
if (diffNumber > 6) {
diffNumber = 6;
}
auto ring = assets.YargRings[diffNumber - 1];
DrawTexturePro(
*ring,
{ 0, 0, (float)ring->width, (float)ring->height },
Placement,
{ 0, 0 },
0,
WHITE
);
}
}

GameMenu::DrawBottomOvershell();
Expand Down
45 changes: 15 additions & 30 deletions Encore/src/menus/cacheLoadingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "raygui.h"
#include "MenuManager.h"
#include "settings/settings.h"
#include "song/cacheload.h"

std::vector<std::string> CacheSplash = {
"Want a break from the cache?",
Expand All @@ -27,26 +28,10 @@ std::vector<std::string> CacheSplash = {
};

void cacheLoadingScreen::Load() {
std::filesystem::path assetsdir = GetApplicationDirectory();
assetsdir /= "Assets";
RedHatDisplay = GameMenu::LoadFontFilter(assetsdir / "fonts/RedHatDisplay-Black.ttf");
RubikBold = GameMenu::LoadFontFilter(assetsdir / "fonts/Rubik-Bold.ttf");
JosefinSansItalic =
GameMenu::LoadFontFilter(assetsdir / "fonts/JosefinSans-Italic.ttf");
encoreLogo = GameMenu::LoadTextureFilter(assetsdir / "encore_favicon-NEW.png");

SplashSel = GetRandomValue(0, CacheSplash.size() - 1);
sdfShader = LoadShader(0, (assetsdir / "fonts/sdf.fs").string().c_str());
}

// todo(3drosalia): make another class for drawing these things without having to uh.
// implement it in every menu class
std::atomic_bool finished = false;
std::atomic_bool started = false;

void LoadCache() {
TheSongList.LoadCache(TheGameSettings.SongPaths);
finished = true;
}

void cacheLoadingScreen::Draw() {
Units u = Units::getInstance();
Expand All @@ -65,25 +50,25 @@ void cacheLoadingScreen::Draw() {
);

GameMenu::mhDrawText(
RedHatDisplay,
ASSET(redHatDisplayBlack),
"LOADING CACHE",
{ u.LeftSide, u.hpct(0.05f) },
u.hinpct(0.125f),
WHITE,
sdfShader,
ASSET(sdfShader),
LEFT
);
float RubikFontSize = u.hinpct(0.05f);
int loaded = CurrentChartNumber;
int toLoad = MaxChartsToLoad;
std::string LoadingText = TextFormat("%d/%d songs loaded", loaded, toLoad);
GameMenu::mhDrawText(
RubikBold,
ASSET(rubikBold),
LoadingText,
{ u.RightSide, u.hpct(0.085f) },
RubikFontSize,
LIGHTGRAY,
sdfShader,
ASSET(sdfShader),
RIGHT
);
GameMenu::DrawBottomOvershell();
Expand All @@ -92,30 +77,30 @@ void cacheLoadingScreen::Draw() {
GetScreenHeight() - u.hpct(0.14f) + u.hinpct(0.07f),
u.hinpct(0.14f),
u.hinpct(0.14f) };

auto logo = ASSETPTR(faviconTex);
DrawTexturePro(
encoreLogo,
{ 0, 0, (float)encoreLogo.width, (float)encoreLogo.height },
*logo,
{ 0, 0, (float)logo->width, (float)logo->height },
LogoRect,
{ u.hinpct(0.07f), u.hinpct(0.07f) },
0,
WHITE
);
GameMenu::mhDrawText(
JosefinSansItalic,
ASSET(josefinSansItalic),
CacheSplash[SplashSel],
{ u.LeftSide + u.hinpct(0.16),
GetScreenHeight() - u.hpct(0.14f) + u.hinpct(0.055f) },
RubikFontSize / 1.5f,
WHITE,
sdfShader,
ASSET(sdfShader),
LEFT
);
if (!started) {
started = true;
std::thread CacheLoader(LoadCache);
CacheLoader.detach();
if (!CacheLoad::started) {
CacheLoad::StartLoad();
}
if (finished) {
if (CacheLoad::finished) {
TheMenuManager.SwitchScreen(MAIN_MENU);
}
}
Expand Down
6 changes: 0 additions & 6 deletions Encore/src/menus/cacheLoadingScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
#include "raylib.h"

class cacheLoadingScreen : public Menu {
Texture2D encoreLogo;
Font RedHatDisplay;
Font RubikBold;
Font JosefinSansItalic;
int SplashSel;
Texture2D LoadingScreenBackground;
Shader sdfShader;

public:
cacheLoadingScreen();
Expand Down
5 changes: 4 additions & 1 deletion Encore/src/menus/gameMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ void MainMenu::Load() {
std::filesystem::path directory = GetPrevDirectoryPath(GetApplicationDirectory());
ChooseSplashText(directory);
PickRandomMenuSong();
if (!mainMenuSet.PollLoaded()) {
mainMenuSet.StartLoad();
}
}
void MainMenu::KeyboardInputCallback(int key, int scancode, int action, int mods) {
if (ThePlayerManager.PlayersActive == 0) {
Expand Down Expand Up @@ -263,7 +266,7 @@ void MainMenu::AttractScreen() {
};

DrawTextEx(
menuAss.josefinSansItalic,
ASSET(josefinSansItalic),
SplashString.c_str(),
GreetSplashPos,
SplashFontSize,
Expand Down
16 changes: 16 additions & 0 deletions Encore/src/song/cacheload.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "cacheload.h"
#include "songlist.h"

std::atomic_bool CacheLoad::finished;
std::atomic_bool CacheLoad::started;
std::thread CacheLoad::cacheLoadThread;

void CacheLoad::StartLoad() {
if (started) return;
started = true;
cacheLoadThread = std::thread([]() {
TheSongList.LoadCache(TheGameSettings.SongPaths);
finished = true;
});
cacheLoadThread.detach();
}
16 changes: 16 additions & 0 deletions Encore/src/song/cacheload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#ifndef CACHELOAD_H
#define CACHELOAD_H
#include <atomic>
#include <thread>
#include "settings/settings.h"

namespace CacheLoad {
extern std::atomic_bool finished;
extern std::atomic_bool started;
extern std::thread cacheLoadThread;

void StartLoad();

}
#endif