loading bar

This commit is contained in:
devZoGok
2025-03-28 19:56:06 +02:00
parent e5377a5152
commit 12c3a67122
13 changed files with 166 additions and 30 deletions
+29
View File
@@ -0,0 +1,29 @@
initPos = {x = 850, y = 100, z = 0}
Size = {x = 200, y = 20}
gui = {
{
guiType = GuiType.TEXT,
text = 'Loading...',
name = 'loading',
pos = initPos,
scale = {x = 0.5, y = 0.5},
font = 'batang.ttf',
fontFirstChar = 0,
fontLastChar = 256,
color = {x = 1, y = 1, z = 1, w = 1}
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = initPos.x, y = initPos.y + Size.y, z = initPos.z},
size = Size,
color = {x = 0, y = 0, z = 0, w = 1}
},
{
guiType = GuiType.GUI_RECTANGLE,
pos = {x = initPos.x + 1, y = initPos.y + Size.y + 1, z = initPos.z + .1},
size = {x = 30, y = Size.y - 2},
name = '_loadingBar',
color = {x = 0, y = 0, z = 1, w = 1}
},
}
+1 -1
View File
@@ -25,7 +25,7 @@ set(BUTTONS statsButton.cpp activeStateButton.cpp minimapButton.cpp ${TRADING_BU
set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp mapListbox.cpp) set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp mapListbox.cpp)
set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp) set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp loadingAppState.cpp)
set(UTIL util.cpp binds.h) set(UTIL util.cpp binds.h)
set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp) set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp) set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp)
+1
View File
@@ -509,6 +509,7 @@ namespace battleship{
return guiRectangle; return guiRectangle;
} }
//TODO distinguish between floats and vector-like tables for scale
Text* ConcreteGuiManager::parseText(int guiId){ Text* ConcreteGuiManager::parseText(int guiId){
sol::state_view SOL_LUA_STATE = generateView(); sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1]; sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
+15 -7
View File
@@ -24,9 +24,9 @@ namespace battleship{
const int maxNumGroups = 10, NUM_MAX_ZOOMS = 75; const int maxNumGroups = 10, NUM_MAX_ZOOMS = 75;
const vb01::u32 IMPASS_NODE_VAL = 65535; const vb01::u32 IMPASS_NODE_VAL = 65535;
const static int numAppStates = 4; const static int numAppStates = 5;
const static int numStaticBinds[numAppStates]{6, 0, 5, 19}; const static int numStaticBinds[numAppStates]{6, 0, 5, 19, 0};
const static int numConfBinds[numAppStates]{0, 1, 27, 0}; const static int numConfBinds[numAppStates]{0, 1, 27, 0, 0};
const static int maxStaticBinds = 19; const static int maxStaticBinds = 19;
const static int maxConfBinds = 23; const static int maxConfBinds = 23;
const static int numScripts = 5; const static int numScripts = 5;
@@ -79,7 +79,8 @@ namespace battleship{
Bind::LOOK_LEFT, Bind::LOOK_LEFT,
Bind::LOOK_RIGHT, Bind::LOOK_RIGHT,
Bind::LOOK_AROUND, Bind::LOOK_AROUND,
} },
{}
}; };
const static Bind confBinds[numAppStates][maxConfBinds]{ const static Bind confBinds[numAppStates][maxConfBinds]{
{}, {},
@@ -111,6 +112,7 @@ namespace battleship{
Bind::SELECT_STRUCTURE, Bind::SELECT_STRUCTURE,
Bind::DESELECT_STRUCTURE Bind::DESELECT_STRUCTURE
}, },
{},
{} {}
}; };
@@ -137,7 +139,8 @@ namespace battleship{
Mapping::MOUSE_AXIS_LEFT, Mapping::MOUSE_AXIS_LEFT,
Mapping::MOUSE_AXIS_RIGHT, Mapping::MOUSE_AXIS_RIGHT,
0 0
} },
{}
}; };
const static int confTriggers[numAppStates][maxConfBinds]{ const static int confTriggers[numAppStates][maxConfBinds]{
{}, {},
@@ -168,6 +171,7 @@ namespace battleship{
GLFW_KEY_B, GLFW_KEY_B,
GLFW_KEY_ESCAPE GLFW_KEY_ESCAPE
}, },
{},
{} {}
}; };
@@ -175,12 +179,14 @@ namespace battleship{
{0, 1, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1},
{}, {},
{0, 0, 0, 0, 1}, {0, 0, 0, 0, 1},
{0, 0, 0, 0, 1} {0, 0, 0, 0, 1},
{}
}; };
const static bool isConfKey[numAppStates][maxConfBinds]{ const static bool isConfKey[numAppStates][maxConfBinds]{
{}, {},
{1}, {1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{},
{} {}
}; };
@@ -188,12 +194,14 @@ namespace battleship{
{1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1},
{}, {},
{0, 0, 0, 0, 1}, {0, 0, 0, 0, 1},
{0, 0, 0, 0, 1} {0, 0, 0, 0, 1},
{}
}; };
const static bool isConfAction[numAppStates][maxConfBinds]{ const static bool isConfAction[numAppStates][maxConfBinds]{
{}, {},
{1}, {1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{},
{} {}
}; };
+2
View File
@@ -59,6 +59,8 @@ namespace battleship{
void InGameAppState::onAttached() { void InGameAppState::onAttached() {
AbstractAppState::onAttached(); AbstractAppState::onAttached();
Map::getSingleton()->loadPlayerGameObjects();
Camera *cam = Root::getSingleton()->getCamera(); Camera *cam = Root::getSingleton()->getCamera();
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm()); cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
+2 -2
View File
@@ -2,6 +2,7 @@
#include "concreteGuiManager.h" #include "concreteGuiManager.h"
#include "gameManager.h" #include "gameManager.h"
#include "mapEditorAppState.h" #include "mapEditorAppState.h"
#include "loadingAppState.h"
#include <stateManager.h> #include <stateManager.h>
@@ -16,8 +17,7 @@ namespace battleship{
void LoadMapButton::OkButton::onClick(){ void LoadMapButton::OkButton::onClick(){
StateManager *sm = GameManager::getSingleton()->getStateManager(); StateManager *sm = GameManager::getSingleton()->getStateManager();
string name = wstringToString(listbox->getContents()[listbox->getSelectedOption()]); string name = wstringToString(listbox->getContents()[listbox->getSelectedOption()]);
sm->attachAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false)); handleLoadingGui(new LoadingAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false), "mapEditor.lua"));
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mapEditor.lua");
} }
LoadMapButton::LoadMapButton(Vector3 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} LoadMapButton::LoadMapButton(Vector3 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){}
+51
View File
@@ -0,0 +1,51 @@
#include "loadingAppState.h"
#include "concreteGuiManager.h"
#include "gameManager.h"
#include "defConfigs.h"
#include <quad.h>
#include <node.h>
#include <vector.h>
#include <assetManager.h>
#include <stateManager.h>
namespace battleship{
using namespace configData;
using namespace gameBase;
using namespace vb01;
using namespace std;
LoadingAppState::LoadingAppState(AbstractAppState *newSt, string newScr) : AbstractAppState(
AppStateType::LOADING_STATE,
configData::calcSumBinds(AppStateType::LOADING_STATE, true),
configData::calcSumBinds(AppStateType::LOADING_STATE, false),
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
),
newState(newSt),
newScreen(newScr)
{}
void LoadingAppState::onDettached(){
GameManager::getSingleton()->getStateManager()->attachAppState(newState);
ConcreteGuiManager::getSingleton()->readLuaScreenScript(newScreen);
AbstractAppState::onDettached();
}
void LoadingAppState::update(){
Node *loadingBar = ConcreteGuiManager::getSingleton()->getGuiRectangle("_loadingBar");
Quad *quad = (Quad*)loadingBar->getMesh(0);
quad->setSize(Vector3((1 - (float)loadableAssets.size() / initNumAssets) * 200.f, 20, 0));
quad->updateVerts(quad->getMeshBase());
if(getTime() - lastUpdateTime > 5){
AssetManager::getSingleton()->load(loadableAssets[0]);
loadableAssets.erase(loadableAssets.begin());
if(loadableAssets.empty()) GameManager::getSingleton()->getStateManager()->dettachAppState(this);
lastUpdateTime = getTime();
}
}
}
+28
View File
@@ -0,0 +1,28 @@
#ifndef LOADING_APP_STATE_H
#define LOADING_APP_STATE_H
#include <abstractAppState.h>
#include <util.h>
namespace battleship{
class LoadingAppState : public gameBase::AbstractAppState{
public:
LoadingAppState(gameBase::AbstractAppState*, std::string);
~LoadingAppState(){}
void onAttached(){}
void onDettached();
void update();
inline void setLoadableAssets(std::vector<std::string> ls){
this->loadableAssets = ls;
initNumAssets = ls.size();
}
private:
int initNumAssets;
std::vector<std::string> loadableAssets;
gameBase::AbstractAppState *newState = nullptr;
std::string newScreen = "";
vb01::s64 lastUpdateTime = 0;
};
}
#endif
+2 -9
View File
@@ -12,6 +12,7 @@
#include <stateManager.h> #include <stateManager.h>
#include "map.h" #include "map.h"
#include "util.h"
#include "game.h" #include "game.h"
#include "player.h" #include "player.h"
#include "gameObject.h" #include "gameObject.h"
@@ -394,16 +395,8 @@ namespace battleship{
//TODO move minimap loading elsewhere //TODO move minimap loading elsewhere
void Map::loadPlayerGameObjects(){ void Map::loadPlayerGameObjects(){
AssetManager *assetManager = AssetManager::getSingleton();
string path = GameManager::getSingleton()->getPath();
assetManager->load(path + DEFAULT_TEXTURE);
sol::state_view SOL_LUA_VIEW = generateView();
string vfxPrefix = SOL_LUA_VIEW["vfxPrefix"], gameObjPrefix = SOL_LUA_VIEW["gameObjPrefix"];
assetManager->load(path + vfxPrefix, true);
assetManager->load(path + gameObjPrefix, true);
int numPlayers = Game::getSingleton()->getNumPlayers(); int numPlayers = Game::getSingleton()->getNumPlayers();
sol::state_view SOL_LUA_VIEW = generateView();
string playerInd = "players"; string playerInd = "players";
for(int i = 0; i < numPlayers; i++){ for(int i = 0; i < numPlayers; i++){
+2 -4
View File
@@ -1,6 +1,7 @@
#include "newMapButton.h" #include "newMapButton.h"
#include "gameManager.h" #include "gameManager.h"
#include "mapEditorAppState.h" #include "mapEditorAppState.h"
#include "loadingAppState.h"
#include "concreteGuiManager.h" #include "concreteGuiManager.h"
#include <stateManager.h> #include <stateManager.h>
@@ -25,10 +26,7 @@ namespace battleship{
atof(wstringToString(sizeX->getText()).c_str()), atof(wstringToString(sizeX->getText()).c_str()),
atof(wstringToString(sizeY->getText()).c_str()) atof(wstringToString(sizeY->getText()).c_str())
); );
StateManager *stateManager = GameManager::getSingleton()->getStateManager(); handleLoadingGui(new LoadingAppState(new MapEditorAppState(wstringToString(name->getText()), size, true), "mapEditor.lua"));
stateManager->attachAppState(new MapEditorAppState(wstringToString(name->getText()), size, true));
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mapEditor.lua");
} }
NewMapButton::NewMapButton(Vector3 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} NewMapButton::NewMapButton(Vector3 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){}
+2 -6
View File
@@ -1,6 +1,7 @@
#include "playButton.h" #include "playButton.h"
#include "gameManager.h" #include "gameManager.h"
#include "inGameAppState.h" #include "inGameAppState.h"
#include "loadingAppState.h"
#include "concreteGuiManager.h" #include "concreteGuiManager.h"
#include "game.h" #include "game.h"
@@ -70,11 +71,6 @@ namespace battleship{
game->addPlayer(new Player(difficulty, faction, team, color, cpuPlayer, i, name)); game->addPlayer(new Player(difficulty, faction, team, color, cpuPlayer, i, name));
} }
map->loadPlayerGameObjects(); handleLoadingGui(new LoadingAppState(new InGameAppState(), "inGame.lua"));
guiManager->readLuaScreenScript("inGame.lua");
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
stateManager->attachAppState(new InGameAppState());
} }
} }
+28
View File
@@ -1,12 +1,16 @@
#include <cmath> #include <cmath>
#include <chrono>
#include <thread>
#include <camera.h> #include <camera.h>
#include <quad.h>
#include <root.h> #include <root.h>
#include <vector.h> #include <vector.h>
#include <util.h> #include <util.h>
#include <assetManager.h> #include <assetManager.h>
#include <stateManager.h> #include <stateManager.h>
#include <solUtil.h>
#include <glm.hpp> #include <glm.hpp>
#include <ext.hpp> #include <ext.hpp>
@@ -16,11 +20,15 @@
#include "util.h" #include "util.h"
#include "defConfigs.h" #include "defConfigs.h"
#include "gameManager.h" #include "gameManager.h"
#include "concreteGuiManager.h"
#include "guiAppState.h" #include "guiAppState.h"
#include "inGameAppState.h" #include "inGameAppState.h"
#include "loadingAppState.h"
#include "mapEditorButton.h" #include "mapEditorButton.h"
using namespace std; using namespace std;
using namespace std::this_thread;
using namespace std::chrono;
using namespace glm; using namespace glm;
using namespace vb01; using namespace vb01;
using namespace vb01Gui; using namespace vb01Gui;
@@ -28,6 +36,26 @@ using namespace vb01Gui;
namespace battleship{ namespace battleship{
using namespace configData; using namespace configData;
void handleLoadingGui(LoadingAppState *loadState){
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
guiManager->readLuaScreenScript("loadingScreen.lua");
sol::state_view SOL_LUA_VIEW = generateView();
string vfxPrefix = SOL_LUA_VIEW["vfxPrefix"], gameObjPrefix = SOL_LUA_VIEW["gameObjPrefix"];
AssetManager *assetManager = AssetManager::getSingleton();
string path = GameManager::getSingleton()->getPath();
vector<string> assets = vector<string>{path + DEFAULT_TEXTURE};
assetManager->readDir(path + vfxPrefix, assets, true);
assetManager->readDir(path + gameObjPrefix, assets, true);
loadState->setLoadableAssets(assets);
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
stateManager->attachAppState(loadState);
}
void makeTitlescreenButtons(GuiAppState *state) { void makeTitlescreenButtons(GuiAppState *state) {
/* /*
class SpButton : public Button { class SpButton : public Button {
+3 -1
View File
@@ -20,10 +20,12 @@ namespace battleship{
typedef int s32; typedef int s32;
typedef long long s64; typedef long long s64;
enum AppStateType{GUI_STATE, IN_GAME_STATE, ACTIVE_STATE, MAP_EDITOR}; enum AppStateType{GUI_STATE, IN_GAME_STATE, ACTIVE_STATE, MAP_EDITOR, LOADING_STATE};
class GuiAppState; class GuiAppState;
class LoadingAppState;
void handleLoadingGui(LoadingAppState*);
void makeTitlescreenButtons(GuiAppState*); void makeTitlescreenButtons(GuiAppState*);
std::vector<std::string> readDir(std::string, bool); std::vector<std::string> readDir(std::string, bool);
vb01::Vector2 spaceToScreen(vb01::Vector3); vb01::Vector2 spaceToScreen(vb01::Vector3);