mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
removed UnitDataManager class
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ set(GUI tooltip.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp)
|
||||
set(CORE gameManager.cpp defConfigs.cpp)
|
||||
set(PROJECTILES projectile.cpp guidedMissile.cpp depthCharge.cpp missile.cpp shell.cpp torpedo.cpp)
|
||||
set(FX explosion.cpp)
|
||||
set(CONTENT player.cpp unitDataManager.cpp unit.cpp pathfinder.cpp map.cpp ${PROJECTILES} ${FX})
|
||||
set(CONTENT player.cpp unit.cpp pathfinder.cpp map.cpp ${PROJECTILES} ${FX})
|
||||
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
|
||||
|
||||
set(SFML_DIR external/SFML)
|
||||
|
||||
+6
-1
@@ -4,6 +4,7 @@
|
||||
#include <vector.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <luaManager.h>
|
||||
|
||||
#include "consoleCommand.h"
|
||||
#include "inGameAppState.h"
|
||||
@@ -57,7 +58,11 @@ namespace battleship{
|
||||
|
||||
int unitId = atoi(fullCommand[2].c_str());
|
||||
|
||||
if(!(0 <= unitId && unitId <= UnitDataManager::getSingleton()->getNumUnits()))
|
||||
LuaManager *lm = LuaManager::getSingleton();
|
||||
string pathBase = GameManager::getSingleton()->getPath() + "Scripts/";
|
||||
lm->buildScript(vector<string>{pathBase + "defPaths.lua", pathBase + "unitData.lua"});
|
||||
|
||||
if(!(0 <= unitId && unitId <= lm->getInt("numUnits")))
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+10
-7
@@ -6,10 +6,10 @@
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <luaManager.h>
|
||||
|
||||
#include "defConfigs.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "unitDataManager.h"
|
||||
#include "consoleCommand.h"
|
||||
#include "vessel.h"
|
||||
|
||||
@@ -197,13 +197,16 @@ namespace battleship{
|
||||
AssetManager *assetManager = AssetManager::getSingleton();
|
||||
assetManager->load(DEFAULT_TEXTURE);
|
||||
|
||||
UnitDataManager *unitDataManager = UnitDataManager::getSingleton();
|
||||
int numUnits = unitDataManager->getNumUnits();
|
||||
string *basePaths = unitDataManager->getBasePath();
|
||||
string *meshPaths = unitDataManager->getMeshPath();
|
||||
LuaManager *lm = LuaManager::getSingleton();
|
||||
string pathBase = GameManager::getSingleton()->getPath() + "Scripts/";
|
||||
lm->buildScript(vector<string>{pathBase + "defPaths.lua", pathBase + "unitData.lua"});
|
||||
int numUnits = lm->getInt("numUnits");
|
||||
|
||||
for(int i = 0; i < numUnits; ++i)
|
||||
assetManager->load(basePaths[i] + meshPaths[i]);
|
||||
for(int i = 0; i < numUnits; ++i){
|
||||
string basePath = lm->getStringFromTable("basePath", vector<Index>{Index(i + 1)});
|
||||
string meshPath = lm->getStringFromTable("meshPath", vector<Index>{Index(i + 1)});
|
||||
assetManager->load(basePath + meshPath);
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onDettached() {}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <ray.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <luaManager.h>
|
||||
|
||||
#include <glm.hpp>
|
||||
#include <ext.hpp>
|
||||
@@ -25,18 +26,7 @@ namespace battleship{
|
||||
this->id = id;
|
||||
this->player = player;
|
||||
|
||||
UnitDataManager *udm = UnitDataManager::getSingleton();
|
||||
health = udm->getHealth()[id];
|
||||
maxTurnAngle = udm->getMaxTurnAngle()[id];
|
||||
range = udm->getRange()[id];
|
||||
lineOfSight = udm->getLineOfSight()[id];
|
||||
speed = udm->getSpeed()[id];
|
||||
unitClass = udm->getUnitClass()[id];
|
||||
type = udm->getUnitType()[id];
|
||||
width = udm->getUnitCornerPoints()[id][0].x - udm->getUnitCornerPoints()[id][1].x;
|
||||
height = udm->getUnitCornerPoints()[id][4].y - udm->getUnitCornerPoints()[id][0].y;
|
||||
length = udm->getUnitCornerPoints()[id][3].z - udm->getUnitCornerPoints()[id][0].z;
|
||||
|
||||
initProperties();
|
||||
initModel();
|
||||
placeUnit(pos);
|
||||
initSound();
|
||||
@@ -46,9 +36,42 @@ namespace battleship{
|
||||
Unit::~Unit() {
|
||||
}
|
||||
|
||||
void Unit::initProperties(){
|
||||
LuaManager *lm = LuaManager::getSingleton();
|
||||
string pathBase = GameManager::getSingleton()->getPath() + "Scripts/";
|
||||
lm->buildScript(vector<string>{pathBase + "defPaths.lua", pathBase + "unitData.lua"});
|
||||
|
||||
health = lm->getIntFromTable("health", vector<Index>{Index(id + 1)});
|
||||
maxHealth = health;
|
||||
|
||||
maxTurnAngle = lm->getFloatFromTable("maxTurnAngle", vector<Index>{Index(id + 1)});
|
||||
range = lm->getFloatFromTable("range", vector<Index>{Index(id + 1)});
|
||||
lineOfSight = lm->getFloatFromTable("lineOfSight", vector<Index>{Index(id + 1)});
|
||||
speed = lm->getFloatFromTable("speed", vector<Index>{Index(id + 1)});
|
||||
unitClass = (UnitClass)lm->getIntFromTable("unitClass", vector<Index>{Index(id + 1)});
|
||||
anglePrecision = lm->getFloatFromTable("anglePrecision", vector<Index>{Index(id + 1)});
|
||||
type = (UnitType)lm->getIntFromTable("unitType", vector<Index>{Index(id + 1)});
|
||||
|
||||
string cornerInd = "unitCornerPoints";
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
float x = lm->getFloatFromTable(cornerInd, vector<Index>{Index(id + 1), Index(i + 1), Index("x")});
|
||||
float y = lm->getFloatFromTable(cornerInd, vector<Index>{Index(id + 1), Index(i + 1), Index("y")});
|
||||
float z = lm->getFloatFromTable(cornerInd, vector<Index>{Index(id + 1), Index(i + 1), Index("z")});
|
||||
corners[i] = Vector3(x, y, z);
|
||||
}
|
||||
|
||||
width = corners[0].x - corners[1].x;
|
||||
height = corners[4].y - corners[0].y;
|
||||
length = corners[3].z - corners[0].z;
|
||||
}
|
||||
|
||||
void Unit::initModel(){
|
||||
UnitDataManager *udm = UnitDataManager::getSingleton();
|
||||
model = new Model(udm->getBasePath()[id] + udm->getMeshPath()[id]);
|
||||
LuaManager *lm = LuaManager::getSingleton();
|
||||
string basePath = lm->getStringFromTable("basePath", vector<Index>{Index(id + 1)});
|
||||
string meshPath = lm->getStringFromTable("meshPath", vector<Index>{Index(id + 1)});
|
||||
|
||||
model = new Model(basePath + meshPath);
|
||||
Root *root = Root::getSingleton();
|
||||
string libPath = root->getLibPath();
|
||||
|
||||
@@ -64,9 +87,10 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Unit::initSound(){
|
||||
UnitDataManager *udm = UnitDataManager::getSingleton();
|
||||
LuaManager *lm = LuaManager::getSingleton();
|
||||
string name = lm->getStringFromTable("name", vector<Index>{Index(id + 1)});
|
||||
selectionSfxBuffer = new sf::SoundBuffer();
|
||||
string p = GameManager::getSingleton()->getPath() + "Sounds/" + udm->getName()[id] + "s/selection.ogg";
|
||||
string p = GameManager::getSingleton()->getPath() + "Sounds/" + name + "s/selection.ogg";
|
||||
|
||||
if(selectionSfxBuffer->loadFromFile(p.c_str()))
|
||||
selectionSfx = new sf::Sound(*selectionSfxBuffer);
|
||||
@@ -127,7 +151,7 @@ namespace battleship{
|
||||
void Unit::displayUnitStats() {
|
||||
float shiftedX = screenPos.x - 0.5 * lenHpBar;
|
||||
hpForegroundNode->setPosition(Vector3(shiftedX, screenPos.y, 0));
|
||||
hpForeground->setSize(Vector3(health / UnitDataManager::getSingleton()->getHealth()[id] * lenHpBar, 10, 0));
|
||||
hpForeground->setSize(Vector3(health / maxHealth * lenHpBar, 10, 0));
|
||||
hpBackgroundNode->setPosition(Vector3(shiftedX, screenPos.y, .1));
|
||||
}
|
||||
|
||||
@@ -173,9 +197,8 @@ namespace battleship{
|
||||
Vector3 linDest = pathPoints[0] + upVec * offset;
|
||||
Vector3 destDir = (linDest - pos).norm();
|
||||
float angle = (destDir != Vector3::VEC_ZERO ? dirVec.getAngleBetween(destDir) : -1);
|
||||
UnitDataManager *udm = UnitDataManager::getSingleton();
|
||||
|
||||
if(angle > udm->getAnglePrecision()[id]){
|
||||
if(angle > anglePrecision){
|
||||
float rotSpeed = (maxTurnAngle > angle ? angle : maxTurnAngle);
|
||||
|
||||
if(leftVec.getAngleBetween(destDir) > PI / 2)
|
||||
@@ -282,11 +305,6 @@ namespace battleship{
|
||||
rot = rotQuat;
|
||||
}
|
||||
|
||||
Vector3 Unit::getCorner(int i) {
|
||||
Vector3 corner = UnitDataManager::getSingleton()->getUnitCornerPoints()[id][i];
|
||||
return pos + (leftVec * corner.x + upVec * corner.y - dirVec * corner.z);
|
||||
}
|
||||
|
||||
std::vector<Projectile*> Unit::getProjectiles(){
|
||||
std::vector<Projectile*> projectiles;
|
||||
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::IN_GAME_STATE));
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
#include "unitDataManager.h"
|
||||
#include "gameManager.h"
|
||||
#include "projectile.h"
|
||||
|
||||
@@ -44,8 +43,9 @@ namespace battleship{
|
||||
};
|
||||
|
||||
enum class MoveDir {LEFT, UP, FORW};
|
||||
|
||||
enum class Corner {FRONT_LEFT, FRONT_RIGHT, REAR_LEFT, REAR_RIGHT};
|
||||
enum class UnitClass {VESSEL, DESTROYER, CRUISER, AIRCRAFT_CARRIER, SUBMARINE, MISSILE_JET, DEMO_JET};
|
||||
enum class UnitType {UNDERWATER, SEA_LEVEL, LAND, AIR};
|
||||
|
||||
class Unit {
|
||||
public:
|
||||
@@ -59,9 +59,9 @@ namespace battleship{
|
||||
void placeUnit(vb01::Vector3);
|
||||
void orientUnit(vb01::Quaternion);
|
||||
void addProjectile(Projectile*);
|
||||
vb01::Vector3 getCorner(int);
|
||||
std::vector<Projectile*> getProjectiles();
|
||||
void addOrder(Order);
|
||||
inline vb01::Vector3 getCorner(int i){return corners[i];}
|
||||
inline bool isSelected(){return selected;}
|
||||
inline bool isSelectable(){return selectable;}
|
||||
inline bool isDebuggable(){return debugging;}
|
||||
@@ -85,6 +85,7 @@ namespace battleship{
|
||||
inline vb01::Vector3 getLeftVec() {return leftVec;}
|
||||
inline vb01::Vector3 getUpVec() {return upVec;}
|
||||
private:
|
||||
void initProperties();
|
||||
void initModel();
|
||||
void initSound();
|
||||
void initUnitStats();
|
||||
@@ -109,13 +110,13 @@ namespace battleship{
|
||||
UnitType type;
|
||||
vb01::Vector2 screenPos;
|
||||
std::vector<Order> orders;
|
||||
vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, 1), leftVec = vb01::Vector3(1, 0, 0);
|
||||
vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, 1), leftVec = vb01::Vector3(1, 0, 0), corners[8];
|
||||
vb01::Quaternion rot = vb01::Quaternion::QUAT_W;
|
||||
int health, cost, id, patrolPointId = 0, playerId;
|
||||
int health, maxHealth, cost, id, patrolPointId = 0, playerId;
|
||||
s64 orderLineDispTime = 0;
|
||||
vb01::Model *model;
|
||||
bool selected = false, selectable, debugging = false, working = true;
|
||||
float lineOfSight, speed, maxTurnAngle, range, width, height, length;
|
||||
float lineOfSight, speed, maxTurnAngle, range, width, height, length, anglePrecision;
|
||||
|
||||
void removeOrder(int);
|
||||
virtual void executeOrders();
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#include "unitDataManager.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
#include <luaManager.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace battleship{
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
UnitDataManager *unitDataManager = nullptr;
|
||||
|
||||
UnitDataManager* UnitDataManager::getSingleton(){
|
||||
if(!unitDataManager)
|
||||
unitDataManager = new UnitDataManager();
|
||||
|
||||
return unitDataManager;
|
||||
}
|
||||
|
||||
UnitDataManager::UnitDataManager(){
|
||||
LuaManager *luaManager = LuaManager::getSingleton();
|
||||
string path = GameManager::getSingleton()->getPath();
|
||||
luaManager->buildScript(vector<string>{path + "Scripts/defPaths.lua", path + "Scripts/unitData.lua"});
|
||||
|
||||
numUnits = luaManager->getInt("numUnits");
|
||||
|
||||
health = new int[numUnits];
|
||||
speed = new float[numUnits];
|
||||
destinationOffset = new float[numUnits];
|
||||
unitType = new UnitType[numUnits];
|
||||
unitClass = new UnitClass[numUnits];
|
||||
anglePrecision = new float[numUnits];
|
||||
cost = new int[numUnits];
|
||||
maxTurnAngle = new float[numUnits];
|
||||
range = new float[numUnits];
|
||||
unitAxisLength = new float[numUnits];
|
||||
lineOfSight = new float[numUnits];
|
||||
name = new string[numUnits];
|
||||
meshPath = new string[numUnits];
|
||||
basePath = new string[numUnits];
|
||||
unitCornerPoints = new Vector3*[numUnits];
|
||||
unitCuboidDimensions = new Vector3*[numUnits];
|
||||
|
||||
for(int i = 0; i < numUnits; i++){
|
||||
health[i] = luaManager->getIntFromTable("health", vector<Index>{Index(i + 1)});
|
||||
speed[i] = luaManager->getFloatFromTable("speed", vector<Index>{Index(i + 1)});
|
||||
unitClass[i] = (UnitClass)luaManager->getIntFromTable("unitClass", vector<Index>{Index(i + 1)});
|
||||
destinationOffset[i] = luaManager->getFloatFromTable("destinationOffset", vector<Index>{Index(i + 1)});
|
||||
unitType[i] = (UnitType)luaManager->getIntFromTable("unitType", vector<Index>{Index(i + 1)});
|
||||
anglePrecision[i] = luaManager->getFloatFromTable("anglePrecision", vector<Index>{Index(i + 1)});
|
||||
cost[i] = luaManager->getIntFromTable("cost", vector<Index>{Index(i + 1)});
|
||||
maxTurnAngle[i] = luaManager->getFloatFromTable("maxTurnAngle", vector<Index>{Index(i + 1)});
|
||||
range[i] = luaManager->getFloatFromTable("range", vector<Index>{Index(i + 1)});
|
||||
unitAxisLength[i] = luaManager->getFloatFromTable("unitAxisLength", vector<Index>{Index(i + 1)});
|
||||
lineOfSight[i] = luaManager->getFloatFromTable("lineOfSight", vector<Index>{Index(i + 1)});
|
||||
name[i] = luaManager->getStringFromTable("name", vector<Index>{Index(i + 1)});
|
||||
meshPath[i] = luaManager->getStringFromTable("meshPath", vector<Index>{Index(i + 1)});
|
||||
basePath[i] = luaManager->getStringFromTable("basePath", vector<Index>{Index(i + 1)});
|
||||
|
||||
unitCornerPoints[i] = new Vector3[8];
|
||||
unitCuboidDimensions[i] = new Vector3[8];
|
||||
|
||||
for(int j = 0; j < 8; j++){
|
||||
float cornerX = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(i + 1), Index(j + 1), Index("x")});
|
||||
float cornerY = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(i + 1), Index(j + 1), Index("y")});
|
||||
float cornerZ = luaManager->getFloatFromTable("unitCornerPoints", vector<Index>{Index(i + 1), Index(j + 1), Index("z")});
|
||||
unitCornerPoints[i][j] = Vector3(cornerX, cornerY, cornerZ);
|
||||
|
||||
float dimX = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(i + 1), Index(j + 1), Index("x")});
|
||||
float dimY = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(i + 1), Index(j + 1), Index("y")});
|
||||
float dimZ = luaManager->getFloatFromTable("unitCuboidDimensions", vector<Index>{Index(i + 1), Index(j + 1), Index("z")});
|
||||
unitCuboidDimensions[i][j] = Vector3(dimX, dimY, dimZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#ifndef UNIT_DATA_MANAGER_H
|
||||
#define UNIT_DATA_MANAGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
namespace battleship{
|
||||
enum class UnitClass {VESSEL, DESTROYER, CRUISER, AIRCRAFT_CARRIER, SUBMARINE, MISSILE_JET, DEMO_JET};
|
||||
|
||||
enum class UnitType {UNDERWATER, SEA_LEVEL, LAND, AIR};
|
||||
|
||||
class UnitDataManager{
|
||||
public:
|
||||
static UnitDataManager* getSingleton();
|
||||
inline int getNumUnits(){return numUnits;}
|
||||
inline int* getHealth(){return health;}
|
||||
inline UnitType* getUnitType(){return unitType;}
|
||||
inline UnitClass* getUnitClass(){return unitClass;}
|
||||
inline float* getMaxTurnAngle(){return maxTurnAngle;}
|
||||
inline float* getRange(){return range;}
|
||||
inline float* getLineOfSight(){return lineOfSight;}
|
||||
inline float* getSpeed(){return speed;}
|
||||
inline float* getAnglePrecision(){return anglePrecision;}
|
||||
inline float* getDestinationOffset(){return destinationOffset;}
|
||||
inline vb01::Vector3** getUnitCornerPoints(){return unitCornerPoints;}
|
||||
inline std::string* getName(){return name;}
|
||||
inline std::string* getBasePath(){return basePath;}
|
||||
inline std::string* getMeshPath(){return meshPath;}
|
||||
private:
|
||||
UnitDataManager();
|
||||
|
||||
int numUnits;
|
||||
UnitType *unitType;
|
||||
UnitClass *unitClass;
|
||||
int *health;
|
||||
float *speed;
|
||||
float *destinationOffset;
|
||||
float *anglePrecision;
|
||||
int *cost;
|
||||
float *maxTurnAngle;
|
||||
float *range;
|
||||
vb01::Vector3 **unitCornerPoints;
|
||||
vb01::Vector3 **unitCuboidDimensions;
|
||||
float *unitAxisLength;
|
||||
float *lineOfSight;
|
||||
std::string *name;
|
||||
std::string *meshPath;
|
||||
std::string *basePath;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user