Moved loading to the fadeout between overworld map and game run state. Added _DEBUG preprocessor checks to prevent debug code from appearing in optimized builds.

pull/29/head
sigonasr2 11 months ago
parent 3e1227a899
commit a2bcee0591
  1. 2
      Adventures in Lestoria/Adventures in Lestoria.tiled-project
  2. 52
      Adventures in Lestoria/AdventuresInLestoria.cpp
  3. 6
      Adventures in Lestoria/AdventuresInLestoria.h
  4. 12
      Adventures in Lestoria/Audio.cpp
  5. 7
      Adventures in Lestoria/Audio.h
  6. 6
      Adventures in Lestoria/State_GameRun.cpp
  7. 3
      Adventures in Lestoria/State_OverworldMap.cpp
  8. 17
      Adventures in Lestoria/TMXParser.h
  9. 18
      Adventures in Lestoria/TODO.txt
  10. 9
      Adventures in Lestoria/TSXParser.h
  11. 2
      Adventures in Lestoria/Toggleable.h
  12. 2
      Adventures in Lestoria/Version.h
  13. 2
      Adventures in Lestoria/assets/Campaigns/1_1_v2.tmx
  14. 3
      Adventures in Lestoria/assets/config/configuration.txt
  15. BIN
      x64/Release/Adventures in Lestoria.exe

@ -15,7 +15,7 @@
"type": "enum",
"values": [
"None",
"foresty_1_1"
"foresty1_1"
],
"valuesAsFlags": false
},

@ -229,6 +229,8 @@ bool AiL::OnUserCreate(){
Inventory::AddItem("Shell Sword");
Inventory::AddItem("Ring of the Slime King",3);
Audio::Initialize();
LoadLevel(LEVEL_NAMES["starting_map"_S]);
ChangePlayerClass(WARRIOR);
@ -243,8 +245,6 @@ bool AiL::OnUserCreate(){
Stats::InitializeDamageReductionTable();
Audio::Initialize();
utils::datafile::INITIAL_SETUP_COMPLETE=true;
ValidateGameStatus(); //Checks to make sure everything has been initialized properly.
@ -851,6 +851,7 @@ void AiL::RenderWorld(float fElapsedTime){
if(!IsForegroundTile(tileSheet,tileSheetIndex)&&!IsUpperForegroundTile(tileSheetIndex)&&!IsReflectiveTile(tileSheet,tileSheetIndex)){
if(layer.tag.data["class"]!="CollisionOnly"){visibleTiles.erase({x,y});}
RenderTile({x,y},tileSheet,tileSheetIndex,{tileSheetX,tileSheetY});
#ifdef _DEBUG
if("debug_collision_boxes"_I){
if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){
geom2d::rect<int>collision=tileSheet.tileset->collision[tileSheetIndex].collision;
@ -858,6 +859,7 @@ void AiL::RenderWorld(float fElapsedTime){
view.DrawRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,GREY);
}
}
#endif
}
}
}
@ -877,6 +879,7 @@ void AiL::RenderWorld(float fElapsedTime){
if(layer.tag.data["class"]!="CollisionOnly"){visibleTiles.erase({x,y});}
RenderTile({x,y},tileSheet,tileSheetIndex,{tileSheetX,tileSheetY});
}
#ifdef _DEBUG
if("debug_collision_boxes"_I){
if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){
geom2d::rect<int>collision=tileSheet.tileset->collision[tileSheetIndex].collision;
@ -884,6 +887,7 @@ void AiL::RenderWorld(float fElapsedTime){
view.DrawRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,GREY);
}
}
#endif
}
}
}break;
@ -1061,12 +1065,14 @@ void AiL::RenderWorld(float fElapsedTime){
int tileSheetX=tileSheetIndex%tileSheetWidth;
int tileSheetY=tileSheetIndex/tileSheetWidth;
view.DrawPartialDecal(vi2d{x,y}*game->GetCurrentMap().tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)},tileSheet.tileset->tileset->Decal(),vi2d{tileSheetX,tileSheetY}*game->GetCurrentMap().tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)},{255,255,255,uint8_t(255-bridgeFadeFactor/TileGroup::FADE_TIME*TileGroup::FADE_AMT)});
#ifdef DEBUG_COLLISIONS
if(tileSheet.tileset.collision.find(tileSheetIndex)!=tileSheet.tileset.collision.end()){
geom2d::rect<int>collision=tileSheet.tileset.collision[tileSheetIndex].collision;
#ifdef _DEBUG
if("debug_collision_boxes"_I){
if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){
geom2d::rect<int>collision=tileSheet.tileset->collision[tileSheetIndex].collision;
view.FillRectDecal(vi2d{x,y}*game->GetCurrentMap().tilewidth+collision.pos,collision.size,{0,0,0,128});
view.DrawRectDecal(vi2d{x,y}*game->GetCurrentMap().tilewidth+collision.pos,collision.size,GREY);
}
}
#endif
}
}
@ -1241,12 +1247,14 @@ void AiL::RenderWorld(float fElapsedTime){
}
}
#ifdef _DEBUG
if(DEBUG_PATHFINDING){
std::vector<vf2d>pathing=game->pathfinder.Solve_AStar(player.get()->GetPos(),GetWorldMousePos(),8,player.get()->OnUpperLevel());
for(vf2d&square:pathing){
view.FillRectDecal(square*float(game->GetCurrentMap().tilewidth),{float(game->GetCurrentMap().tilewidth),float(game->GetCurrentMap().tilewidth)},DARK_GREEN);
}
}
#endif
}
Player*AiL::GetPlayer(){
@ -1293,6 +1301,7 @@ void AiL::RenderHud(){
DrawShadowStringPropDecal(vf2d{float(ScreenWidth()/2),float(ScreenHeight()/4)-24}-GetTextSizeProp(displayText)/2,displayText,BLUE,VERY_DARK_BLUE);
}
DisplayBossEncounterInfo();
#ifdef _DEBUG
if("debug_player_info"_I){
DrawShadowStringDecal({0,128},player->GetPos().str());
DrawShadowStringDecal({0,136},"Spd: "+std::to_string(player->GetMoveSpdMult()));
@ -1303,7 +1312,9 @@ void AiL::RenderHud(){
}
DrawShadowStringDecal({0,1},"Selection: "+Menu::menus[INVENTORY_CONSUMABLES]->selection.str());
DrawShadowStringDecal({0,12},"Button Hold Time: "+std::to_string(Menu::menus[INVENTORY_CONSUMABLES]->buttonHoldTime));
}}
}
#endif
}
void AiL::RenderCooldowns(){
std::vector<Ability>cooldowns{
@ -1784,6 +1795,12 @@ void AiL::LoadLevel(MapName map){
camera.MoveCamera(cameraStartPos);
pathfinder.Initialize();
Audio::SetAudioEvent("Default Volume");
game->audioEngine.fullyLoaded=true; //We assume there's no audio to load, so we just set the audio as fully loaded by default.
if(MAP_DATA[map].bgmSongName.length()>0){
Audio::PlayBGM(MAP_DATA[map].bgmSongName);
DisableFadeIn(true);
}
}
bool AiL::IsUpperForegroundTile(int tileID){
@ -2075,12 +2092,14 @@ datafile operator ""_A(const char*key,std::size_t len){
}
void AiL::OutputDebugInfo(const char*key,std::size_t len){
#ifdef _DEBUG
if(utils::datafile::DEBUG_ACCESS_OPTIONS){
std::string k=std::string(key);
if(!k.starts_with("debug_")){
std::cout<<"Reading "<<k<<std::endl;
}
}
#endif
}
bool AiL::IsReflectiveTile(TilesheetData tileSheet,int tileID){
@ -2473,6 +2492,9 @@ void AiL::ClearLoadoutItem(int slot){
}
void AiL::RenderFadeout(){
if(Audio::BGMFullyLoaded()){
game->DisableFadeIn(false);
}
uint8_t alpha=0;
if(fadeOutDuration>0){
fadeOutDuration=std::max(0.f,fadeOutDuration-GetElapsedTime());
@ -2482,14 +2504,26 @@ void AiL::RenderFadeout(){
alpha=uint8_t(util::lerp(0,255,1-(fadeOutDuration/fadeOutTotalTime)));
}else
if(fadeInDuration>0){
if(!disableFadeIn){
fadeInDuration=std::max(0.f,fadeInDuration-GetElapsedTime());
alpha=uint8_t(util::lerp(255,0,1-(fadeInDuration/fadeOutTotalTime)));
}else{
alpha=255;
}
}
FillRectDecal({0,0},GetScreenSize(),{0,0,0,alpha});
#ifdef _DEBUG
if("debug_transition_info"_I){
DrawShadowStringDecal({2,2},"Alpha: "+std::to_string(alpha));
DrawShadowStringDecal({2,14},"Disable Fade In: "+std::to_string(disableFadeIn));
DrawShadowStringDecal({2,26},"Fully Loaded: "+std::to_string(audioEngine.fullyLoaded));
}
#endif
}
bool AiL::GamePaused(){
return fadeOutDuration>0;
return fadeOutDuration>0||disableFadeIn;
}
void AiL::EndGame(){
@ -2586,3 +2620,7 @@ std::string operator ""_FS(const char*key,std::size_t len){
AiL::OutputDebugInfo(key,len);
return DATA.GetProperty(std::string(key,len)).GetFullString();
}
void AiL::DisableFadeIn(const bool disable){
disableFadeIn=disable;
}

@ -111,13 +111,14 @@ private:
int chapter=1; //We start at chapter 1.
std::array<std::shared_ptr<Item>,3>loadout;
float fadeOutDuration=0;
float fadeOutTotalTime=0;
float fadeInDuration=0;
States::State transitionState=States::State::GAME_RUN;
bool gameEnd=false;
std::vector<Monster>monstersToBeSpawned;
time_t gameStarted;
std::function<void(std::string_view)>responseCallback;
float fadeInDuration=0;
float fadeOutTotalTime=0;
bool disableFadeIn=false;
void ValidateGameStatus();
#ifndef __EMSCRIPTEN__
@ -213,6 +214,7 @@ public:
void InitializePlayerLevelCap();
void ResetGame();
void OnRequestCompleted(const std::string_view receivedData)const override;
void DisableFadeIn(const bool disable);
struct TileGroupData{
vi2d tilePos;

@ -98,6 +98,8 @@ void Audio::Initialize(){
defaultFadeTime=data.GetReal();
}
}
Self().bgm.SetInitialized();
}
MiniAudio&Audio::Engine(){
@ -108,6 +110,7 @@ void Audio::Play(const std::string_view sound){
};
void Audio::PlayBGM(const std::string_view sound,const bool loop){
BGM&track=Self().bgm[std::string(sound)];
Self().fullyLoaded=false;
StopBGM(); //Stop any currently playing track.
Self().playParams={std::string(sound),loop};
Self().playBGMWaitTime=0.7f;
@ -131,13 +134,15 @@ const Volume&Audio::BGM::GetVolume(const Event&eventName,const ChannelID&id)cons
}
void Audio::BGM::Load(){
if(Self().BGMIsPlaying()){
BGM&bgm=Self().bgm[Self().currentBGM];
if(Self().BGMIsPlaying()){
bgm.Unload();
}
}
Self().currentBGM=songFileName;
BGM&newBgm=Self().bgm[songFileName];
if(newBgm.channels.size()>0)ERR(std::format("WARNING! The size of the channels list is greater than zero! Size: {}",bgm.channels.size()));
if(newBgm.channels.size()>0)ERR(std::format("WARNING! The size of the channels list is greater than zero! Size: {}",newBgm.channels.size()));
for(const ChannelName&channel:newBgm.GetChannels()){
ChannelID soundID=Engine().LoadSound("bgm_directory"_S+channel);
newBgm.channels.push_back(soundID);
@ -242,6 +247,11 @@ void Audio::Update(){
Engine().Play(trackID,Self().playParams.loop);
channelListIndex++;
}
Self().fullyLoaded=true;
}
}
}
const bool Audio::BGMFullyLoaded(){
return Self().fullyLoaded;
}

@ -39,6 +39,7 @@ All rights reserved.
#include "olcPGEX_MiniAudio.h"
#include "config.h"
#include <set>
#include "safemap.h"
using SongName=std::string;
using Event=std::string;
@ -49,6 +50,7 @@ using Volume=float;
using VolumeList=std::vector<Volume>;
class Audio{
friend class AiL;
public:
static Audio&Self();
static MiniAudio&Engine();
@ -62,6 +64,7 @@ public:
static const SongName&GetTrackName();
static void SetAudioEvent(const Event&eventName);
static const bool BGMIsPlaying();
static const bool BGMFullyLoaded(); //Fully loaded means when the audio buffer has finished filling up, which means sound is now playing.
private:
struct BGMPlayParams{
std::string sound;
@ -100,11 +103,11 @@ private:
private:
MiniAudio audioEngine;
SongName currentBGM="";
std::map<SongName,BGM>bgm;
safemap<SongName,BGM>bgm;
std::set<Event>events;
static float defaultFadeTime;
Event currentAudioEvent="Default Volume";
bool fullyLoaded=true;
float playBGMWaitTime=0.0f;
BGMPlayParams playParams;
};

@ -41,9 +41,11 @@ All rights reserved.
#include "Menu.h"
#include "ItemDrop.h"
#include "VisualNovel.h"
#include "State_OverworldMap.h"
INCLUDE_MONSTER_LIST
INCLUDE_game
INCLUDE_LEVEL_NAMES
void State_GameRun::OnStateChange(GameState*prevState){
if(Menu::IsMenuOpen()){
@ -52,6 +54,7 @@ void State_GameRun::OnStateChange(GameState*prevState){
game->GetPlayer()->SetState(State::NORMAL);
port=ViewPort::rectViewPort({0,0},{240,240},{24,24});
#pragma region Test Text Decal Creation
if(r.Decal()==nullptr){
r.Create(240,240);
game->SetDrawTarget(r.Sprite());
@ -66,6 +69,9 @@ void State_GameRun::OnStateChange(GameState*prevState){
game->SetDrawTarget(nullptr);
r.Decal()->Update();
}
#pragma endregion
game->LoadLevel(LEVEL_NAMES.at(State_OverworldMap::GetCurrentConnectionPoint().map));
}
void State_GameRun::OnUserUpdate(AiL*game){
game->bossDisplayTimer=std::max(0.f,game->bossDisplayTimer-game->GetElapsedTime());

@ -215,8 +215,7 @@ void State_OverworldMap::StartLevel(){
if(State_OverworldMap::GetCurrentConnectionPoint().map.starts_with("STORY")){
VisualNovel::LoadVisualNovel(State_OverworldMap::GetCurrentConnectionPoint().map);
}else{
game->LoadLevel(LEVEL_NAMES.at(State_OverworldMap::GetCurrentConnectionPoint().map));
GameState::ChangeState(States::GAME_RUN);
GameState::ChangeState(States::GAME_RUN,0.3f);
}
}

@ -95,6 +95,7 @@ struct Map{
std::vector<XMLTag> TilesetData;
std::vector<LayerTag> LayerData;
std::string mapType="";
std::string bgmSongName="";
std::set<std::string>spawns;
std::map<int,SpawnerTag> SpawnerData; //Spawn groups have IDs, mobs associate which spawner they are tied to via this ID.
std::map<std::string,std::vector<::ZoneData>> ZoneData;
@ -144,6 +145,7 @@ class TMXParser{
#ifdef TMX_PARSER_SETUP
#undef TMX_PARSER_SETUP
#include "State_OverworldMap.h"
extern bool _MAP_LOAD_INFO;
extern bool _DEBUG_MAP_LOAD_INFO;
const std::string XMLTag::FormatTagData(std::map<std::string,std::string>tiles){
std::string displayStr="";
@ -285,7 +287,9 @@ class TMXParser{
if(valid&&data.length()>0){
if (newTag.tag.length()==0) { //Tag's empty, so first line is the tag.
newTag.tag=data;
#if _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Tag: "<<newTag.tag<<"\n";
#endif
} else {
std::string key = data.substr(0,data.find("="));
std::string value = data.substr(data.find("=")+1,std::string::npos);
@ -295,7 +299,9 @@ class TMXParser{
value = value.substr(0,value.length()-1);
newTag.data[key]=value;
#if _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<" "<<key<<":"<<newTag.data[key]<<"\n";
#endif
}
}
}
@ -340,6 +346,9 @@ class TMXParser{
if (newTag.tag=="property"&&newTag.data["name"]=="Level Type") {
parsedMapInfo.mapType=newTag.data["value"];
} else
if (newTag.tag=="property"&&newTag.data["name"]=="Background Music") {
parsedMapInfo.bgmSongName=newTag.data["value"];
} else
if (newTag.tag=="object"&&newTag.data["type"]=="PlayerSpawnLocation") {
parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2};
} else
@ -379,9 +388,13 @@ class TMXParser{
prevZoneData=&zones.back();
}
}else{
#if _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n";
#endif
}
#if _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n";
#endif
}
TMXParser::TMXParser(std::string file){
std::ifstream f(file,std::ios::in);
@ -426,7 +439,9 @@ class TMXParser{
}
if(infiniteMap){
#if _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Infinite map detected. Parsing stopped early."<<std::endl;
#endif
}
for(XMLTag&monster:accumulatedMonsterTags){
@ -490,6 +505,8 @@ class TMXParser{
counter++;
}
#ifdef _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Map Data:\n"<<parsedMapInfo<<"\n";
#endif
}
#endif

@ -1,11 +1,6 @@
January 1st
===========
The Hub / NPC Interactions
Save/Load Game
EMSCRIPTEN Version: ???
NEW GAME -> Ask for a User ID -> Ask for a Save File Name -> Saves the Game -> Starts the Game
LOAD GAME -> Ask for a User ID -> Shows Available Files -> Click to Load -> Start Game
Audio Engine
- Audio Ambience Zones
- Menu Sound Effects
@ -21,7 +16,13 @@ Settings Menu
-We have to save keybinds to the save file.
-Smooth Movement
-Click on title screen should not process as input immediately.
-Investigate why frame rate matters for intro screen.
-Warrior slash should occur even with no target
-Add in other story plates
-Faster main menu screen transition
-Simplify map collision tiles by removing the requirement for hidden boundaries.
-Loading should happen on fadeout.
January 31st
============
@ -47,3 +48,10 @@ Story proofreading/correcting/storyboarding
- Export/Import Save Files Online/Offline
- Consider controls for fine-tuning music and how they sound during events.
- Lock up unimplemented classes.
- Emscripten _DEBUG flag add as an option when building

@ -178,11 +178,15 @@ class TSXParser{
TileCollisionData data;
data.collision=geom2d::rect<int>{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}};
if(parsedTilesetInfo.CollisionData.count(previousTagID)){
if(_DEBUG_MAP_LOAD_INFO)ERR("WARNING! There was already collision data defined for tile "<<previousTagID<<"!")
#ifdef _DEBUG
if(_DEBUG_MAP_LOAD_INFO)ERR("WARNING! There was already collision data defined for tile "<<previousTagID<<"!");
#endif
}
parsedTilesetInfo.CollisionData[previousTagID]=data;
}
#ifdef _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n";
#endif
}
TSXParser::TSXParser(std::string file)
:previousTagID(-1){
@ -214,7 +218,8 @@ class TSXParser{
}
}
}
#ifdef _DEBUG
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Tileset Data:\n"<<parsedTilesetInfo<<"\n";
#endif
}
#endif

@ -65,9 +65,11 @@ public:
}
inline IToggleable(){
uninitializedToggleGroupItems.push_back(this);
#ifdef _DEBUG
if("debug_toggleable_items"_I){
std::cout<<"\tInitialized Toggle Item Ptr: 0x"<<std::hex<<this<<std::endl;
}
#endif
}
protected:
std::vector<IToggleable*>toggleGroup;

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 5395
#define VERSION_BUILD 5414
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" class="Map" orientation="orthogonal" renderorder="right-down" width="205" height="205" tilewidth="24" tileheight="24" infinite="0" backgroundcolor="#475500" nextlayerid="9" nextobjectid="164">
<properties>
<property name="Background Music" propertytype="BGM" value="foresty_1_1"/>
<property name="Background Music" propertytype="BGM" value="foresty1_1"/>
<property name="Level Type" propertytype="LevelType" value="Dungeon"/>
</properties>
<tileset firstgid="1" source="../maps/Tilesheet_No_Shadow24x24.tsx"/>

@ -107,6 +107,9 @@ debug_access_options = 0
# Shows map loading output
debug_map_load_info = 0
# Shows state transition information
debug_transition_info = 0
# Shows extra info about the player on the HUD
debug_player_info = 0

Loading…
Cancel
Save