Merge pull request #304 from devZoGok/revert-279-bf-255-minimaps-updating

Revert "Fixed Minimap Updating"
This commit is contained in:
devZoGok
2026-08-21 06:46:19 +00:00
committed by GitHub
9 changed files with 14 additions and 94 deletions
-1
View File
@@ -1 +0,0 @@
\build
+1 -20
View File
@@ -9,7 +9,7 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pedantic")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDART 17)
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
set(CMAKE_BUILD_TYPE Debug)
set(BUILD_TESTS OFF)
@@ -50,16 +50,6 @@ set(GAME_BASE_DIR external/gameBase)
add_executable(${GAME_NAME} main.cpp ${GAME_SRC})
# Do this for Windows
if(MSVC)
target_compile_options(${GAME_NAME} PRIVATE
/bigobj
# /utf-8
# /UUNICODE
# /U_UNICODE
)
endif()
include_directories(external/tinydir)
include_directories(external/vb01/external/glm)
include_directories(external/vb01/external/glm/glm)
@@ -91,15 +81,6 @@ if(BUILD_TESTS)
set(TEST_NAME battleshipTests)
add_executable(${TEST_NAME} ${TEST_SRC})
# Do this for Windows
if(MSVC)
target_compile_options(${TEST_NAME} PRIVATE
/bigobj
# /utf-8
# /UUNICODE
# /U_UNICODE
)
endif()
target_include_directories(${TEST_NAME} PUBLIC ${VB01_DIR})
target_include_directories(${TEST_NAME} PUBLIC ${VB01_GUI_DIR})
target_include_directories(${TEST_NAME} PUBLIC ${GAME_BASE_DIR})
-13
View File
@@ -49,13 +49,11 @@ namespace battleship{
ConcreteGuiManager::ConcreteGuiManager(){
string assetPath = GameManager::getSingleton()->getPath();
// These base paths are used for when the LUA GUI entries refer to textures or font
texBasePath = assetPath + "Textures/";
fontBasePath = assetPath + "Fonts/";
}
ConcreteGuiManager* ConcreteGuiManager::getSingleton(){
// Return the single already created concreteGui Mangner
if(!concreteGuiManager)
concreteGuiManager = new ConcreteGuiManager();
@@ -162,7 +160,6 @@ namespace battleship{
case EXPORT:
button = new ExportButton(pos, size);
break;
// This case begins the gameplay
case PLAY:{
int mid = guiTable["dependencies"][1]["id"];
Listbox *mapListbox = (MapListbox*)guiElements[mid].second;
@@ -545,7 +542,6 @@ namespace battleship{
return text;
}
/// @brief Parse the music variables from the Lua script
void ConcreteGuiManager::parseMusic(){
sol::state_view SOL_STATE_VIEW = generateView();
sol::optional<sol::table> musicTblOpt = SOL_STATE_VIEW["music"];
@@ -574,7 +570,6 @@ namespace battleship{
sm->play(trackPaths, 100, delay, loop, shuffle);
}
// Parses the passed lua script and removes any existing GUI elements (the removal is for switching between screens)
void ConcreteGuiManager::readLuaScreenScript(
string script,
vector<Button*> buttonExceptions,
@@ -611,19 +606,12 @@ namespace battleship{
parseLuaScript(script);
}
/// @brief Parses a lua script to display its GUI screen defined in the it
/// @param script
/// @param luaCode
void ConcreteGuiManager::parseLuaScript(string script, string luaCode){
guiElements.clear();
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
// Creates a shared lua state if it doesn't exist and wraps it in a state view for convenient C++ access
// It the state exists then it just creates a state view wrapper around the same state
sol::state_view SOL_LUA_VIEW = generateView();
// Set the music to nil since not every screen has a music value to override the one from the last screen
SOL_LUA_VIEW.script("music = nil");
// Loads and executes the passed lua script inside the shared lua state, creating variables from the passed script that can be accessed
SOL_LUA_VIEW.script_file(basePath + script);
if(luaCode != "") SOL_LUA_VIEW.script(luaCode);
@@ -631,7 +619,6 @@ namespace battleship{
SOL_LUA_VIEW.script("numGui = #gui");
int numGuiElements = SOL_LUA_VIEW["numGui"];
// Go through all the GUI entriies in mainMenu.lua and based on their type add the correspondding element
for(int i = 0; i < numGuiElements; i++){
int guiTypeId = SOL_LUA_VIEW["gui"][i + 1]["guiType"];
-7
View File
@@ -251,8 +251,6 @@ namespace battleship{
);
}
/// @brief Sets the name of the directory where all the files are located as the passed game directory
/// @param gameDir
void GameManager::initLua(string gameDir){
sol::state_view SOL_LUA_STATE = generateView();
@@ -262,7 +260,6 @@ namespace battleship{
for(string f : configData::scripts)
SOL_LUA_STATE.script_file(path + f);
// Gets the minimap Lua script
SOL_LUA_STATE.script_file(path + "Scripts/Gui/_minimap.lua");
sol::table resTable = SOL_LUA_STATE["graphics"]["resolution"];
@@ -270,14 +267,11 @@ namespace battleship{
height = resTable["y"];
}
/// @brief Starts game execution
/// @param gameDir is the game directory all the game files are stored in
void GameManager::start(string gameDir) {
running = true;
registerMembers();
initLua(gameDir);
// I beliieve this sets the game window width and height and name (last variable), I'm not for sure about the path
Root *root = Root::getSingleton();
root->start(width, height, path + "../external/vb01/", "Battleship");
@@ -285,7 +279,6 @@ namespace battleship{
inputManager = new InputManager(stateManager, root->getWindow());
}
/// @brief Updates the sound, input, and state manager along with the root of the game engine
void GameManager::update() {
Root::getSingleton()->update();
SoundManager::getSingleton()->update();
+2 -5
View File
@@ -15,7 +15,6 @@ using namespace vb01;
using namespace std;
int main(int argc, char **argv) {
// Get the executable's name as the game path
string gamePath = string(argv[0]);
for(int i = 0; i < gamePath.length(); i++)
@@ -23,16 +22,14 @@ int main(int argc, char **argv) {
gamePath[i] = '/';
gamePath = gamePath.substr(0, gamePath.find_last_of("/") + 1) + "../";
// Start the game manager and pass the game path to it
GameManager *gm = GameManager::getSingleton();
gm->start(gamePath);
// Get the state manager and attach a new Gui app state
gm->getStateManager()->attachAppState(new GuiAppState());
AssetManager::getSingleton()->load(gm->getPath() + "Fonts/batang.ttf");
// Begin on the main menu GUI
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mainMenu.lua");
// As long as the game manager is running, update it
while(gm->isRunning()){
gm->update();
}
+3 -33
View File
@@ -42,14 +42,11 @@ namespace battleship{
return minimap;
}
// Minimap constructor
Map::Minimap::Minimap(){
// Gets map size
Vector3 mapSize = Map::getSingleton()->getMapSize();
float ratio = mapSize.x / mapSize.z;
sol::state_view SOL_LUA_VIEW = generateView();
// Set the minimap size
SOL_LUA_VIEW.script_file(GameManager::getSingleton()->getPath() + "Scripts/Gui/activeGameState.lua");
sol::table sizeTbl = SOL_LUA_VIEW["minimapSize"];
float initSizeX = sizeTbl["x"], initSizeY = sizeTbl["y"];
@@ -77,7 +74,6 @@ namespace battleship{
camIcon = initIcon(Root::getSingleton()->getCamera()->getPosition(), basePath + camIconFile);
}
// Minimap destructor
Map::Minimap::~Minimap(){
Node *guiNode = Root::getSingleton()->getGuiNode();
@@ -92,13 +88,7 @@ namespace battleship{
delete camIcon;
}
/// @brief Initialize an icon for the minimap by passing its path and poition on the map
/// @param posOnMap
/// @param iconPath
/// @return
Node* Map::Minimap::initIcon(Vector3 posOnMap, string iconPath){
// Get the icon image, its size, and texture
string p[]{iconPath};
ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(iconPath);
Vector3 iconSize = Vector3(asset->width, asset->height, 0);
@@ -109,7 +99,6 @@ namespace battleship{
mat->addBoolUniform("texturingEnabled", true);
mat->addTexUniform("diffuseMap", tex, false);
// Get the minimap size and position on the screen
sol::state_view SOL_LUA_VIEW = generateView();
sol::table posTbl = SOL_LUA_VIEW["minimapPos"],
_posTbl = SOL_LUA_VIEW["_minimapPos"],
@@ -120,16 +109,14 @@ namespace battleship{
Vector3 minimapPos = Vector3((float)_posTbl["x"], (float)posTbl["y"] + (float)_posTbl["y"], (float)posTbl["z"]);
Vector3 mapSize = Map::getSingleton()->getMapSize();
// Use the minimap size and the map size to place the icon on the minimap in a position corresponding to its position in the real map
Vector2 iconPos = Vector2(
minimapSize.x * (posOnMap.x + .5 * mapSize.x) / mapSize.x,
minimapSize.y * (posOnMap.z + .5 * mapSize.z) / mapSize.z
);
// Create a quad rendering the icon UI element
Quad *quad = new Quad(iconSize, false);
quad->setMaterial(mat);
// Attach the quad to a GUI node of the icon's size and position
Node *node = new Node(minimapPos + Vector3(iconPos.x, iconPos.y, .05) - .5 * iconSize);
node->attachMesh(quad);
root->getGuiNode()->attachChild(node);
@@ -138,29 +125,24 @@ namespace battleship{
}
//TODO add a flag to Player::getUnits* whether to include garrisoned units
/// @brief Updates the minimap according to the real map
void Map::Minimap::updateImage(){
GameManager *gm = GameManager::getSingleton();
Map *map = Map::getSingleton();
// Get the entire minimap image
string imagePath = gm->getPath() + "Models/Maps/" + map->getMapName() + "/minimap.jpg";
ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(imagePath);
int width = asset->width, height = asset->height;
Vector3 mapSize = map->getMapSize();
// Stores the positions of the friendly units
vector<pair<Unit*, Vector2>> unitMinimapPos;
// Get the current game state
ActiveGameState *activeState = (ActiveGameState*)gm->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
// Go through all the units on the player's team and get their map position to convert to minimap coordinates to store in the minimap positions
for(Player *pl : Game::getSingleton()->getPlayers(true))
if(pl->getTeam() == activeState->getPlayer()->getTeam()){
vector<Unit*> units = pl->getUnits();
for(Unit *u : units){
// Skip adding all the garrisonable units
if(u->isVehicle() && ((Vehicle*)u)->getGarrisonable()) continue;
Vector2 coords = Vector2(
@@ -174,7 +156,6 @@ namespace battleship{
int pxId = 0, numChannels = asset->numChannels, size = width * height * numChannels;
float losFactor = .6;
// Darkens the entire minimap
for(u8 *p = asset->image; p != asset->image + size; p += numChannels, pxId += numChannels){
*(p + 0) = losFactor * oldImageData[pxId + 0];
*(p + 1) = losFactor * oldImageData[pxId + 1];
@@ -183,13 +164,11 @@ namespace battleship{
int unitPxRadius = 1;
// Go through all the minimap positions and
for(pair<Unit*, Vector2> unitPair : unitMinimapPos){
Unit *losUnit = unitPair.first;
Vector2 losUnitCoords = unitPair.second;
float minimapLos = losUnit->getLineOfSight() / mapSize.x * width;
// Restore brightness based on if the units are in the LOS radius
for(int x = max(-.5f * width, losUnitCoords.x - minimapLos); x < min(.5f * width, losUnitCoords.x + minimapLos); x++){
for(int y = max(-.5f * height, losUnitCoords.y - minimapLos); y < min(.5f * height, losUnitCoords.y + minimapLos); y++){
int pxId = width * (y + .5 * height) + (x + .5 * width);
@@ -199,8 +178,7 @@ namespace battleship{
asset->image[numChannels * pxId + 0] = oldImageData[numChannels * pxId + 0];
asset->image[numChannels * pxId + 1] = oldImageData[numChannels * pxId + 1];
asset->image[numChannels * pxId + 2] = oldImageData[numChannels * pxId + 2];
// Color the areas inside visible regions near the friendly unit minimap positions with the current player's color
// This only shows friendly units in the line of sight, should that be the case?
for(pair<Unit*, Vector2> addUnitPair : unitMinimapPos)
if(fabs(addUnitPair.second.x - coords.x) < unitPxRadius && fabs(addUnitPair.second.y - coords.y) < unitPxRadius){
Vector3 unitCol = addUnitPair.first->getPlayer()->getColor();
@@ -215,15 +193,12 @@ namespace battleship{
}
}
// Load the minimap image data
Node *rectNode = ConcreteGuiManager::getSingleton()->getButton("minimap")->getRectNode();
Material *mat = rectNode->getMesh(0)->getMaterial();
Texture *tex = ((Material::TextureUniform*)mat->getUniform("diffuseMap"))->value;
tex->loadImageData(asset, false);
}
/// @brief Updates the position of the camera positiion icon GUI that goes on the minimap to where the camera is currently in the real map
/// @param minimapButton
void Map::Minimap::updateCamFrame(Button *minimapButton){
Vector3 camPos = Root::getSingleton()->getCamera()->getPosition();
Vector3 mapSize = Map::getSingleton()->getMapSize();
@@ -233,18 +208,14 @@ namespace battleship{
minimapSize.y * (camPos.z + .5 * mapSize.z) / mapSize.z
);
// Overlay the icon on the minimap by using the minimap's position
camIcon->setPosition(minimapButton->getPos() + Vector3(iconPos.x, iconPos.y, .06));
}
/// @brief Updates the minimap unit positions and cam frame icon as long as the application state is active
void Map::Minimap::update(){
Button *mb = ConcreteGuiManager::getSingleton()->getButton("minimap");
if(!(GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE) && mb)) return;
updateImage();
updateCamFrame(mb);
}
@@ -308,7 +279,6 @@ namespace battleship{
return edges;
}
/// @brief Update the minimap
void Map::update(){
Minimap::getSingleton()->update();
}
+2 -2
View File
@@ -69,7 +69,7 @@ namespace battleship{
};
static Map* getSingleton();
~Map(){} // Destructor is public
~Map(){}
static std::vector<Edge> generateAdjacentNodeEdges(int, int, int, int, int);
void update();
void load(std::string);
@@ -111,7 +111,7 @@ namespace battleship{
std::vector<vb01::Node*> lights;
std::vector<std::pair<Cell::Type, std::vector<Cell*>>> regions;
Map(){} // Constructor is private
Map(){}
void preprareScene(bool);
void loadSpawnPoints();
void loadLights();
-5
View File
@@ -17,7 +17,6 @@ namespace battleship{
PlayButton::PlayButton(Listbox *ml, Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate), mapListbox(ml) {}
// Starts the gameplay
void PlayButton::onClick() {
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
vector<Listbox*> factionsListboxes, difficultiesListboxes, colorsListboxes, teamsListboxes;
@@ -31,7 +30,6 @@ namespace battleship{
else if(name == "teams") teamsListboxes.push_back(listbox);
}
// Initialize the game
Game *game = Game::getSingleton();
game->initTechnologies();
@@ -75,9 +73,6 @@ namespace battleship{
game->addPlayer(new Player(difficulty, faction, team, color, cpuPlayer, i, name));
}
// HUD GUI for during gameplay
// The loading app state passed is an InGameAppState for the selected map with the inGame.lua script for the screen
// The initial state of the current map is used to populate the HUD GUI here
handleLoadingGui(new LoadingAppState(new InGameAppState(mapName), "inGame.lua"));
}
}
-2
View File
@@ -36,8 +36,6 @@ using namespace vb01Gui;
namespace battleship{
using namespace configData;
/// @brief Pushes the loadable assets from asset manager as a state to the state manager stack
/// @param loadState
void handleLoadingGui(LoadingAppState *loadState){
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
guiManager->readLuaScreenScript("loadingScreen.lua");