*added split(s,d) function for strings
*reading unit xml healthbar node *adjusted hpbars
This commit is contained in:
parent
034b6066be
commit
de5135bfaf
|
@ -5223,9 +5223,6 @@ void Game::render3d(){
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
//renderOnTopBars (aka Healthbars)
|
|
||||||
renderer.renderOnTopBars();
|
|
||||||
|
|
||||||
//objects
|
//objects
|
||||||
renderer.renderObjects(avgRenderFps);
|
renderer.renderObjects(avgRenderFps);
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
|
@ -5254,6 +5251,9 @@ void Game::render3d(){
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
|
||||||
|
|
||||||
|
//renderOnTopBars (aka Healthbars)
|
||||||
|
renderer.renderOnTopBars();
|
||||||
|
|
||||||
//particles
|
//particles
|
||||||
renderer.renderParticleManager(rsGame);
|
renderer.renderParticleManager(rsGame);
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderParticleManager]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderParticleManager]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||||
|
|
|
@ -5634,11 +5634,33 @@ void Renderer::renderOnTopBars(){
|
||||||
for(int visibleUnitIndex = 0;
|
for(int visibleUnitIndex = 0;
|
||||||
visibleUnitIndex < (int)qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) {
|
visibleUnitIndex < (int)qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) {
|
||||||
Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex];
|
Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex];
|
||||||
Vec3f currVec= unit->getCurrVectorFlat();
|
if(unit->isAlive() && unit->getType()->isHealthbarEnabled()
|
||||||
if(unit->getType()->getMaxEp() > 0) {
|
&& ((unit->getType()->getHealthbarVisible()&hbvAlways)
|
||||||
renderSelectionHpBar((currVec+Vec3f(0,unit->getType()->getHeight(),0)),unit->getType()->getSize(),unit->getHpRatio(),0.08,unit->getEpRatio());
|
|| ((unit->getType()->getHealthbarVisible()&hbvDamaged) && unit->getHp()!=unit->getType()->getMaxHp())
|
||||||
} else {
|
|| ((unit->getType()->getHealthbarVisible()&hbvSelected) && game->getGui()->isSelected(unit)))) {
|
||||||
renderSelectionHpBar((currVec+Vec3f(0,unit->getType()->getHeight(),0)),unit->getType()->getSize(),unit->getHpRatio(),0.05);
|
Vec3f currVec= unit->getCurrVectorFlat();
|
||||||
|
float thickness;
|
||||||
|
if(unit->getType()->getHealthbarHeight()==-100.0f) {
|
||||||
|
currVec.y+=unit->getType()->getHeight()+1;
|
||||||
|
} else {
|
||||||
|
currVec.y+=unit->getType()->getHealthbarHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(unit->getType()->getHealthbarThickness()==-1.0f) {
|
||||||
|
if(unit->getType()->getMaxEp() > 0 && unit->getType()->isHealthbarShowEp()) {
|
||||||
|
thickness=0.08f;
|
||||||
|
} else {
|
||||||
|
thickness=0.05f;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
thickness=unit->getType()->getHealthbarThickness();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(unit->getType()->getMaxEp() > 0 && unit->getType()->isHealthbarShowEp()) {
|
||||||
|
renderSelectionHpBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),thickness,unit->getEpRatio());
|
||||||
|
} else {
|
||||||
|
renderSelectionHpBar(currVec,unit->getType()->getSize(),unit->getHpRatio(),thickness);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8253,13 +8275,12 @@ void Renderer::enableProjectiveTexturing() {
|
||||||
void Renderer::renderSelectionHpBar(Vec3f v, int size, float hp, float height, float ep) {
|
void Renderer::renderSelectionHpBar(Vec3f v, int size, float hp, float height, float ep) {
|
||||||
Vec3f rightVector;
|
Vec3f rightVector;
|
||||||
Vec3f upVector;
|
Vec3f upVector;
|
||||||
Vec3f posUpVector=Vec3f(0,1,0);
|
v.y+=1;
|
||||||
v+=posUpVector;
|
|
||||||
float modelview[16];
|
float modelview[16];
|
||||||
float width=size/2+0.5f;
|
float width=(float)size/6+0.25f;
|
||||||
float red;
|
float red;
|
||||||
float green;
|
float green;
|
||||||
float brightness=0.6f;
|
float brightness=0.7f;
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -8269,12 +8290,6 @@ void Renderer::renderSelectionHpBar(Vec3f v, int size, float hp, float height, f
|
||||||
rightVector= Vec3f(modelview[0], modelview[4], modelview[8]);
|
rightVector= Vec3f(modelview[0], modelview[4], modelview[8]);
|
||||||
upVector= Vec3f(modelview[1], modelview[5], modelview[9]);
|
upVector= Vec3f(modelview[1], modelview[5], modelview[9]);
|
||||||
|
|
||||||
// vertexBuffer[bufferIndex] = pos - (rightVector - upVector) * size;
|
|
||||||
// vertexBuffer[bufferIndex+1] = pos - (rightVector + upVector) * size;
|
|
||||||
// vertexBuffer[bufferIndex+2] = pos + (rightVector - upVector) * size;
|
|
||||||
// vertexBuffer[bufferIndex+3] = pos + (rightVector + upVector) * size;
|
|
||||||
|
|
||||||
//printf("size:%f\n",size);
|
|
||||||
hp=hp*2-1;
|
hp=hp*2-1;
|
||||||
ep=ep*2-1;
|
ep=ep*2-1;
|
||||||
|
|
||||||
|
@ -8286,7 +8301,7 @@ void Renderer::renderSelectionHpBar(Vec3f v, int size, float hp, float height, f
|
||||||
green=brightness+hp*brightness;
|
green=brightness+hp*brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
glColor4f(red,green,0.0f,1.0f);
|
glColor4f(red,green,0.0f,0.4f);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
if(ep < -2.0f) {
|
if(ep < -2.0f) {
|
||||||
glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
|
glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
|
||||||
|
@ -8296,20 +8311,20 @@ void Renderer::renderSelectionHpBar(Vec3f v, int size, float hp, float height, f
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
|
glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
|
||||||
glVertex3fv((v - (rightVector*width + upVector*height*0.1f)).ptr());
|
glVertex3fv((v - (rightVector*width + upVector*height*0.0f)).ptr());
|
||||||
glVertex3fv((v + (rightVector*hp*width - upVector*height*0.1f)).ptr());
|
glVertex3fv((v + (rightVector*hp*width - upVector*height*0.0f)).ptr());
|
||||||
glVertex3fv((v + (rightVector*hp*width + upVector*height)).ptr());
|
glVertex3fv((v + (rightVector*hp*width + upVector*height)).ptr());
|
||||||
|
|
||||||
glColor4f(brightness/2,brightness/2,brightness,1.0f);
|
glColor4f(brightness,0,brightness,0.4f);
|
||||||
glVertex3fv((v - (rightVector*width + upVector*height*0.1f)).ptr());
|
glVertex3fv((v - (rightVector*width + upVector*height*0.0f)).ptr());
|
||||||
glVertex3fv((v - (rightVector*width + upVector*height)).ptr());
|
glVertex3fv((v - (rightVector*width + upVector*height)).ptr());
|
||||||
glVertex3fv((v + (rightVector*ep*width - upVector*height)).ptr());
|
glVertex3fv((v + (rightVector*ep*width - upVector*height)).ptr());
|
||||||
glVertex3fv((v + (rightVector*ep*width - upVector*height*0.1f)).ptr());
|
glVertex3fv((v + (rightVector*ep*width - upVector*height*0.0f)).ptr());
|
||||||
printf("Found Ep Unit\n");
|
printf("Found Ep Unit\n");
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glColor4f(red+0.1f,green+0.1f,0.1f,1.0f);
|
glColor4f(red+0.1f,green+0.1f,0.1f,0.5f);
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
|
glVertex3fv((v - (rightVector*width - upVector*height)).ptr());
|
||||||
glVertex3fv((v - (rightVector*width + upVector*height)).ptr());
|
glVertex3fv((v - (rightVector*width + upVector*height)).ptr());
|
||||||
|
|
|
@ -88,6 +88,11 @@ UnitType::UnitType() : ProducibleType() {
|
||||||
meetingPointImage = NULL;
|
meetingPointImage = NULL;
|
||||||
lightColor= Vec3f(0.f);
|
lightColor= Vec3f(0.f);
|
||||||
light= false;
|
light= false;
|
||||||
|
healthbar= false;
|
||||||
|
healthbarShowEp= true;
|
||||||
|
healthbarheight= -100.0f;
|
||||||
|
healthbarthickness=-1.0f;
|
||||||
|
healthbarVisible=hbvUndefined; //TODO Implement default
|
||||||
multiSelect= false;
|
multiSelect= false;
|
||||||
commandable= true;
|
commandable= true;
|
||||||
armorType= NULL;
|
armorType= NULL;
|
||||||
|
@ -446,6 +451,40 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//healthbar
|
||||||
|
if(parametersNode->hasChild("healthbar")) {
|
||||||
|
const XmlNode *HealthbarNode= parametersNode->getChild("healthbar");
|
||||||
|
healthbar= HealthbarNode->getAttribute("enabled")->getBoolValue();
|
||||||
|
if(healthbar){
|
||||||
|
if(HealthbarNode->hasAttribute("show-ep")) {
|
||||||
|
healthbarShowEp= HealthbarNode->getAttribute("show-ep")->getBoolValue();
|
||||||
|
}
|
||||||
|
if(HealthbarNode->hasAttribute("height")) {
|
||||||
|
healthbarheight= HealthbarNode->getAttribute("height")->getFloatValue();
|
||||||
|
}
|
||||||
|
if(HealthbarNode->hasAttribute("thickness")) {
|
||||||
|
healthbarthickness= HealthbarNode->getAttribute("thickness")->getFloatValue(0.f, 1.f);
|
||||||
|
}
|
||||||
|
if(HealthbarNode->hasAttribute("visible")) {
|
||||||
|
string healthbarVisibleString=HealthbarNode->getAttribute("visible")->getValue();
|
||||||
|
healthbarVisible=hbvUndefined;
|
||||||
|
vector<string> v=split(healthbarVisibleString,"|");
|
||||||
|
for (int i = 0; i < (int)v.size(); ++i) {
|
||||||
|
string current=trim(v[i]);
|
||||||
|
if(current=="always") {
|
||||||
|
healthbarVisible=healthbarVisible|hbvAlways;
|
||||||
|
} else if(current=="selected") {
|
||||||
|
healthbarVisible=healthbarVisible|hbvSelected;
|
||||||
|
} else if(current=="damaged") {
|
||||||
|
healthbarVisible=healthbarVisible|hbvDamaged;
|
||||||
|
} else {
|
||||||
|
throw megaglest_runtime_error("Unknown Healthbar Visible Option: " + current, validationMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//light
|
//light
|
||||||
const XmlNode *lightNode= parametersNode->getChild("light");
|
const XmlNode *lightNode= parametersNode->getChild("light");
|
||||||
light= lightNode->getAttribute("enabled")->getBoolValue();
|
light= lightNode->getAttribute("enabled")->getBoolValue();
|
||||||
|
|
|
@ -116,6 +116,13 @@ enum UnitClass {
|
||||||
|
|
||||||
typedef vector<UnitParticleSystemType*> DamageParticleSystemTypes;
|
typedef vector<UnitParticleSystemType*> DamageParticleSystemTypes;
|
||||||
|
|
||||||
|
enum HealthbarVisible {
|
||||||
|
hbvUndefined=0,
|
||||||
|
hbvAlways=1,
|
||||||
|
hbvDamaged=2,
|
||||||
|
hbvSelected=4
|
||||||
|
};
|
||||||
|
|
||||||
enum UnitCountsInVictoryConditions {
|
enum UnitCountsInVictoryConditions {
|
||||||
ucvcNotSet,
|
ucvcNotSet,
|
||||||
ucvcTrue,
|
ucvcTrue,
|
||||||
|
@ -170,6 +177,11 @@ private:
|
||||||
const ArmorType *armorType;
|
const ArmorType *armorType;
|
||||||
bool light;
|
bool light;
|
||||||
Vec3f lightColor;
|
Vec3f lightColor;
|
||||||
|
bool healthbar;
|
||||||
|
bool healthbarShowEp;
|
||||||
|
float healthbarheight;
|
||||||
|
float healthbarthickness;
|
||||||
|
int healthbarVisible;
|
||||||
bool multiSelect;
|
bool multiSelect;
|
||||||
bool commandable;
|
bool commandable;
|
||||||
int sight;
|
int sight;
|
||||||
|
@ -256,6 +268,11 @@ public:
|
||||||
inline bool getLight() const {return light;}
|
inline bool getLight() const {return light;}
|
||||||
inline bool getRotationAllowed() const {return rotationAllowed;}
|
inline bool getRotationAllowed() const {return rotationAllowed;}
|
||||||
inline Vec3f getLightColor() const {return lightColor;}
|
inline Vec3f getLightColor() const {return lightColor;}
|
||||||
|
inline bool isHealthbarEnabled() const {return healthbar;}
|
||||||
|
inline bool isHealthbarShowEp() const {return healthbarShowEp;}
|
||||||
|
inline float getHealthbarHeight() const {return healthbarheight;}
|
||||||
|
inline float getHealthbarThickness() const {return healthbarthickness;}
|
||||||
|
inline int getHealthbarVisible() const {return healthbarVisible;}
|
||||||
inline bool getMultiSelect() const {return multiSelect;}
|
inline bool getMultiSelect() const {return multiSelect;}
|
||||||
inline bool isCommandable() const {return commandable;}
|
inline bool isCommandable() const {return commandable;}
|
||||||
inline int getSight() const {return sight;}
|
inline int getSight() const {return sight;}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define _SHARED_UTIL_UTIL_H_
|
#define _SHARED_UTIL_UTIL_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
@ -226,6 +227,7 @@ string cutLastFile(const string &s);
|
||||||
string cutLastExt(const string &s);
|
string cutLastExt(const string &s);
|
||||||
string ext(const string &s);
|
string ext(const string &s);
|
||||||
string replaceBy(const string &s, char c1, char c2);
|
string replaceBy(const string &s, char c1, char c2);
|
||||||
|
vector<string> split(string s,string d);
|
||||||
string toLower(const string &s);
|
string toLower(const string &s);
|
||||||
void copyStringToBuffer(char *buffer, int bufferSize, const string& s);
|
void copyStringToBuffer(char *buffer, int bufferSize, const string& s);
|
||||||
|
|
||||||
|
|
|
@ -709,6 +709,22 @@ string replaceBy(const string &s, char c1, char c2){
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> split(string s,string d) {
|
||||||
|
vector<string> results;
|
||||||
|
size_t lastOffset = 0;
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
size_t offset = s.find_first_of(d, lastOffset);
|
||||||
|
results.push_back(s.substr(lastOffset, offset - lastOffset));
|
||||||
|
if (offset == string::npos)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
lastOffset = offset + d.size(); //skip the delimiter
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
string toLower(const string &s){
|
string toLower(const string &s){
|
||||||
string rs= s;
|
string rs= s;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue