- added support for showing projectile particles in the g3d viewer

This commit is contained in:
Mark Vejvoda 2010-06-24 10:52:58 +00:00
parent 0340d57a8d
commit a81286cbba
23 changed files with 853 additions and 54 deletions

View File

@ -110,7 +110,7 @@ if $(WX_AVAILABLE) = "yes" {
GLEST_VIEWER_SOURCES += [ Wildcard $(i) : *.cpp *.h ] ;
}
Application glest_g3dviewer : $(GLEST_VIEWER_SOURCES) ../glest_game/graphics/unit_particle_type.cpp ;
Application glest_g3dviewer : $(GLEST_VIEWER_SOURCES) ../glest_game/graphics/unit_particle_type.cpp ../glest_game/graphics/particle_type.cpp ;
LinkWith glest_g3dviewer : glestlib strefloplib ;
ExternalLibs glest_g3dviewer : SDL GL GLU XERCES VORBIS VORBISFILE OGG OPENAL LUA JPEG PNG CURL WX X11 ;
IncludeDir glest_g3dviewer : ../shared_lib/include/$(LIB_INCLUDE_DIRS) $(GLEST_VIEWER_DIRS) ../glest_game/graphics ../glest_game/global ../glest_game/sound ../glest_game/game ;

View File

@ -2,7 +2,6 @@
#include <stdexcept>
//#include "graphics_factory_gl.h"
#include "model_gl.h"
#include "graphics_interface.h"
#include "util.h"
@ -68,6 +67,7 @@ MainWindow::MainWindow(const string &modelPath)
menuFile= new wxMenu();
menuFile->Append(miFileLoad, wxT("Load"));
menuFile->Append(miFileLoadParticleXML, wxT("Load Particle XML"));
menuFile->Append(miFileLoadProjectileParticleXML, wxT("Load Projectile Particle XML"));
menu->Append(menuFile, wxT("File"));
//mode
@ -192,6 +192,16 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
}
}
void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
string fileName;
wxFileDialog fileDialog(this);
fileDialog.SetWildcard(wxT("XML files (*.xml)|*.xml"));
if(fileDialog.ShowModal()==wxID_OK){
string path = (const char*)wxFNCONV(fileDialog.GetPath().c_str());
loadProjectileParticle(path);
}
}
void MainWindow::loadModel(string path) {
if(path != "" && fileExists(path) == true) {
this->modelPathList.push_back(path);
@ -215,6 +225,8 @@ void MainWindow::loadParticle(string path) {
}
if(this->particlePathList.size() > 0) {
renderer->initModelManager();
for(int idx = 0; idx < this->particlePathList.size(); idx++) {
string particlePath = this->particlePathList[idx];
string dir= extractDirectoryPathFromFile(particlePath);
@ -245,7 +257,7 @@ void MainWindow::loadParticle(string path) {
std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType();
unitParticleSystemType->load(dir, dir + "/" + particlePath, renderer->getNewTexture2D());
unitParticleSystemType->load(dir, dir + "/" + particlePath, renderer);
unitParticleSystemTypes.push_back(unitParticleSystemType);
for(std::vector<UnitParticleSystemType *>::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) {
@ -269,6 +281,87 @@ void MainWindow::loadParticle(string path) {
}
}
void MainWindow::loadProjectileParticle(string path) {
if(path != "" && fileExists(path) == true) {
this->particleProjectilePathList.push_back(path);
}
if(this->particleProjectilePathList.size() > 0) {
renderer->initModelManager();
for(int idx = 0; idx < this->particleProjectilePathList.size(); idx++) {
string particlePath = this->particleProjectilePathList[idx];
string dir= extractDirectoryPathFromFile(particlePath);
size_t pos = dir.find_last_of("/");
if(pos == dir.length()-1) {
dir.erase(dir.length() -1);
}
particlePath= extractFileFromDirectoryPath(particlePath);
std::string unitXML = dir + "/" + extractFileFromDirectoryPath(dir) + ".xml";
int size = -1;
int height = -1;
if(fileExists(unitXML) == true) {
XmlTree xmlTree;
xmlTree.load(unitXML);
const XmlNode *unitNode= xmlTree.getRootNode();
const XmlNode *parametersNode= unitNode->getChild("parameters");
//size
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
//height
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
}
std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
XmlTree xmlTree;
xmlTree.load(dir + "/" + particlePath);
const XmlNode *particleSystemNode= xmlTree.getRootNode();
std::cout << "Loaded successfully, loading values..." << std::endl;
ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(dir, dir + "/" + particlePath,renderer);
std::cout << "Values loaded, about to read..." << std::endl;
projectileParticleSystemTypes.push_back(projectileParticleSystemType);
for(std::vector<ParticleSystemTypeProjectile *>::const_iterator it= projectileParticleSystemTypes.begin(); it != projectileParticleSystemTypes.end(); ++it) {
ProjectileParticleSystem *ps = (*it)->create();
if(size > 0) {
Vec3f vec = Vec3f(0.f, height / 2.f, 0.f);
//ps->setPos(vec);
Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f);
ps->setPath(vec, vec2);
}
ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0,0));
projectileParticleSystems.push_back(ps);
ps->setVisible(true);
renderer->manageParticleSystem(ps);
//psProj= pstProj->create();
//psProj->setPath(startPos, endPos);
//psProj->setObserver(new ParticleDamager(unit, this, gameCamera));
//psProj->setVisible(visible);
//psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmap()->getPixel3f(0,0));
//renderer.manageParticleSystem(psProj, rsGame);
}
renderer->initTextureManager();
}
}
}
void MainWindow::onMenuModeNormals(wxCommandEvent &event){
renderer->toggleNormals();
menuMode->Check(miModeNormals, renderer->getNormals());
@ -465,6 +558,7 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_CLOSE(MainWindow::onClose)
EVT_MENU(miFileLoad, MainWindow::onMenuFileLoad)
EVT_MENU(miFileLoadParticleXML, MainWindow::onMenuFileLoadParticleXML)
EVT_MENU(miFileLoadProjectileParticleXML, MainWindow::onMenuFileLoadProjectileParticleXML)
EVT_MENU(miModeWireframe, MainWindow::onMenuModeWireframe)
EVT_MENU(miModeNormals, MainWindow::onMenuModeNormals)

View File

@ -33,6 +33,7 @@ public:
enum MenuId{
miFileLoad,
miFileLoadParticleXML,
miFileLoadProjectileParticleXML,
miModeWireframe,
miModeNormals,
miModeGrid,
@ -62,6 +63,7 @@ private:
//string ParticlePath;
std::vector<string> modelPathList;
std::vector<string> particlePathList;
std::vector<string> particleProjectilePathList;
float speed;
float anim;
@ -72,8 +74,12 @@ private:
std::vector<UnitParticleSystemType *> unitParticleSystemTypes;
std::vector<UnitParticleSystem *> unitParticleSystems;
std::vector<ParticleSystemTypeProjectile *> projectileParticleSystemTypes;
std::vector<ProjectileParticleSystem *> projectileParticleSystems;
void loadModel(string path);
void loadParticle(string path);
void loadProjectileParticle(string path);
public:
MainWindow(const string &modelPath);
@ -86,6 +92,7 @@ public:
void onClose(wxCloseEvent &event);
void onMenuFileLoad(wxCommandEvent &event);
void onMenuFileLoadParticleXML(wxCommandEvent &event);
void onMenuFileLoadProjectileParticleXML(wxCommandEvent &event);
void onMenuModeNormals(wxCommandEvent &event);
void onMenuModeWireframe(wxCommandEvent &event);
void onMenuModeGrid(wxCommandEvent &event);

View File

@ -78,7 +78,7 @@ Renderer::Renderer(){
modelRenderer = NULL;
textureManager = NULL;
particleRenderer = NULL;
particleManager = NULL;
modelManager = NULL;
}
Renderer::~Renderer(){
@ -88,6 +88,7 @@ Renderer::~Renderer(){
//resources
delete particleManager;
delete modelManager;
}
Renderer * Renderer::getInstance(){
@ -141,6 +142,11 @@ Texture2D * Renderer::getNewTexture2D() {
return newTexture;
}
Model * Renderer::getNewModel() {
Model *newModel = modelManager->newModel();
return newModel;
}
void Renderer::init(){
assertGl();
@ -157,6 +163,9 @@ void Renderer::init(){
//resources
particleManager= gf->newParticleManager();
modelManager = gf->newModelManager();
modelManager->setTextureManager(textureManager);
//red tex
customTextureRed= textureManager->newTexture2D();
customTextureRed->getPixmap()->init(1, 1, 3);
@ -293,6 +302,7 @@ void Renderer::loadTheModel(Model *model, string file){
model->setTextureManager(textureManager);
model->loadG3d(file);
textureManager->init();
modelManager->init();
}
void Renderer::renderTheModel(Model *model, float f){
@ -355,10 +365,15 @@ void Renderer::initTextureManager() {
textureManager->init();
}
void Renderer::initModelManager() {
modelManager->init();
}
void Renderer::end() {
//delete resources
//textureManager->end();
particleManager->end();
modelManager->end();
}
}}//end namespace

View File

@ -14,12 +14,15 @@
#include "texture.h"
#include "particle_renderer.h"
#include "model_manager.h"
#include "graphics_interface.h"
//#include "model_manager.h"
//#include "graphics_factory_gl.h"
using Shared::Graphics::ModelRenderer;
using Shared::Graphics::TextureManager;
using Shared::Graphics::ModelManager;
using Shared::Graphics::Model;
using Shared::Graphics::Texture2D;
using Shared::Graphics::ParticleRenderer;
@ -31,6 +34,8 @@ using Shared::Graphics::MeshCallback;
using Shared::Graphics::Mesh;
using Shared::Graphics::Texture;
using namespace Shared::Graphics;
namespace Shared{ namespace G3dViewer{
// ===============================================
@ -50,7 +55,7 @@ public:
// class Renderer
// ===============================
class Renderer{
class Renderer : public RendererInterface {
public:
static const int windowX= 100;
static const int windowY= 100;
@ -75,6 +80,7 @@ private:
ParticleRenderer *particleRenderer;
ParticleManager *particleManager;
ModelManager *modelManager;
Texture2D *customTextureRed;
Texture2D *customTextureBlue;
@ -110,8 +116,16 @@ public:
void updateParticleManager();
void renderParticleManager();
Texture2D *getPlayerColorTexture(PlayerColor playerColor);
Texture2D * getNewTexture2D();
Model * getNewModel();
Model *newModel(ResourceScope rs) { return getNewModel(); }
Texture2D *newTexture2D(ResourceScope rs) { return getNewTexture2D(); }
void initTextureManager();
void initModelManager();
void end();
};

View File

@ -44,14 +44,23 @@ Logger::~Logger(){
}
void Logger::cleanupLoadingTexture() {
if(loadingTexture!=NULL)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(loadingTexture!=NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance();
Texture *genericTexture = loadingTexture;
renderer.endTexture(rsGlobal,&genericTexture);
//renderer.endTexture(rsGlobal,loadingTexture);
loadingTexture->end();
delete loadingTexture;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//delete loadingTexture;
loadingTexture=NULL;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
Logger & Logger::getInstance(){
@ -106,8 +115,12 @@ void Logger::loadLoadingScreen(string filepath){
//loadingTexture->getPixmap()->load(filepath);
loadingTexture->load(filepath);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance();
renderer.initTexture(rsGlobal,loadingTexture);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
}

View File

@ -141,8 +141,11 @@ void Game::load(){
Config &config = Config::getInstance();
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
//bool skipCustomLoadScreen = true;
bool skipCustomLoadScreen = false;
string scenarioDir = "";
if(gameSettings.getScenarioDir() != "") {
if(skipCustomLoadScreen == false && gameSettings.getScenarioDir() != "") {
scenarioDir = gameSettings.getScenarioDir();
if(EndsWith(scenarioDir, ".xml") == true) {
scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4);
@ -168,7 +171,7 @@ void Game::load(){
sleep(0);
//SDL_PumpEvents();
if(loadingImageUsed == false){
if(skipCustomLoadScreen == false && loadingImageUsed == false){
// try to use a faction related loading screen
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Searching for faction loading screen\n",__FILE__,__FUNCTION__);
for ( int i=0; i < gameSettings.getFactionCount(); ++i ) {
@ -205,7 +208,7 @@ void Game::load(){
}
}
}
if(loadingImageUsed == false){
if(skipCustomLoadScreen == false && loadingImageUsed == false){
// try to use a tech related loading screen
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Searching for tech loading screen\n",__FILE__,__FUNCTION__);

View File

@ -0,0 +1,267 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2010-2010 Titus Tscharntke
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "particle_type.h"
#include "util.h"
#include "core_data.h"
#include "xml_parser.h"
#include "model.h"
#include "config.h"
#include "game_constants.h"
#include "leak_dumper.h"
using namespace Shared::Xml;
using namespace Shared::Graphics;
namespace Glest{ namespace Game{
// =====================================================
// class ParticleSystemType
// =====================================================
ParticleSystemType::ParticleSystemType() {
teamcolorNoEnergy=false;
teamcolorEnergy=false;
texture=NULL;
model=NULL;
}
void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir,RendererInterface *renderer) {
//texture
const XmlNode *textureNode= particleSystemNode->getChild("texture");
bool textureEnabled= textureNode->getAttribute("value")->getBoolValue();
if(textureEnabled){
texture= renderer->newTexture2D(rsGame);
if(textureNode->getAttribute("luminance")->getBoolValue()){
texture->setFormat(Texture::fAlpha);
texture->getPixmap()->init(1);
}
else{
texture->getPixmap()->init(4);
}
texture->load(dir + "/" + textureNode->getAttribute("path")->getRestrictedValue());
}
else {
texture= NULL;
}
//model
const XmlNode *modelNode= particleSystemNode->getChild("model");
bool modelEnabled= modelNode->getAttribute("value")->getBoolValue();
if(modelEnabled) {
string path= modelNode->getAttribute("path")->getRestrictedValue();
model= renderer->newModel(rsGame);
model->load(dir + "/" + path);
}
else{
model= NULL;
}
//primitive
const XmlNode *primitiveNode= particleSystemNode->getChild("primitive");
primitive= primitiveNode->getAttribute("value")->getRestrictedValue();
//offset
const XmlNode *offsetNode= particleSystemNode->getChild("offset");
offset.x= offsetNode->getAttribute("x")->getFloatValue();
offset.y= offsetNode->getAttribute("y")->getFloatValue();
offset.z= offsetNode->getAttribute("z")->getFloatValue();
//color
const XmlNode *colorNode= particleSystemNode->getChild("color");
color.x= colorNode->getAttribute("red")->getFloatValue(0.f, 1.0f);
color.y= colorNode->getAttribute("green")->getFloatValue(0.f, 1.0f);
color.z= colorNode->getAttribute("blue")->getFloatValue(0.f, 1.0f);
color.w= colorNode->getAttribute("alpha")->getFloatValue(0.f, 1.0f);
//color
const XmlNode *colorNoEnergyNode= particleSystemNode->getChild("color-no-energy");
colorNoEnergy.x= colorNoEnergyNode->getAttribute("red")->getFloatValue(0.f, 1.0f);
colorNoEnergy.y= colorNoEnergyNode->getAttribute("green")->getFloatValue(0.f, 1.0f);
colorNoEnergy.z= colorNoEnergyNode->getAttribute("blue")->getFloatValue(0.f, 1.0f);
colorNoEnergy.w= colorNoEnergyNode->getAttribute("alpha")->getFloatValue(0.f, 1.0f);
//size
const XmlNode *sizeNode= particleSystemNode->getChild("size");
size= sizeNode->getAttribute("value")->getFloatValue();
//sizeNoEnergy
const XmlNode *sizeNoEnergyNode= particleSystemNode->getChild("size-no-energy");
sizeNoEnergy= sizeNoEnergyNode->getAttribute("value")->getFloatValue();
//speed
const XmlNode *speedNode= particleSystemNode->getChild("speed");
speed= speedNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
//gravity
const XmlNode *gravityNode= particleSystemNode->getChild("gravity");
gravity= gravityNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
//emission rate
const XmlNode *emissionRateNode= particleSystemNode->getChild("emission-rate");
emissionRate= emissionRateNode->getAttribute("value")->getIntValue();
//energy max
const XmlNode *energyMaxNode= particleSystemNode->getChild("energy-max");
energyMax= energyMaxNode->getAttribute("value")->getIntValue();
//speed
const XmlNode *energyVarNode= particleSystemNode->getChild("energy-var");
energyVar= energyVarNode->getAttribute("value")->getIntValue();
//teamcolorNoEnergy
if(particleSystemNode->hasChild("teamcolorNoEnergy")){
const XmlNode *teamcolorNoEnergyNode= particleSystemNode->getChild("teamcolorNoEnergy");
teamcolorNoEnergy= teamcolorNoEnergyNode->getAttribute("value")->getBoolValue();
}
//teamcolorEnergy
if(particleSystemNode->hasChild("teamcolorEnergy")){
const XmlNode *teamcolorEnergyNode= particleSystemNode->getChild("teamcolorEnergy");
teamcolorEnergy= teamcolorEnergyNode->getAttribute("value")->getBoolValue();
}
//mode
if(particleSystemNode->hasChild("mode")){
const XmlNode *modeNode= particleSystemNode->getChild("mode");
mode= modeNode->getAttribute("value")->getRestrictedValue();
}
else
{
mode="normal";
}
}
void ParticleSystemType::setValues(AttackParticleSystem *ats){
ats->setTexture(texture);
ats->setPrimitive(AttackParticleSystem::strToPrimitive(primitive));
ats->setOffset(offset);
ats->setColor(color);
ats->setColorNoEnergy(colorNoEnergy);
ats->setSpeed(speed);
ats->setGravity(gravity);
ats->setParticleSize(size);
ats->setSizeNoEnergy(sizeNoEnergy);
ats->setEmissionRate(emissionRate);
ats->setMaxParticleEnergy(energyMax);
ats->setVarParticleEnergy(energyVar);
ats->setModel(model);
ats->setTeamcolorNoEnergy(teamcolorNoEnergy);
ats->setTeamcolorEnergy(teamcolorEnergy);
ats->setBlendMode(ParticleSystem::strToBlendMode(mode));
}
// ===========================================================
// class ParticleSystemTypeProjectile
// ===========================================================
void ParticleSystemTypeProjectile::load(const string &dir, const string &path,RendererInterface *renderer) {
try{
XmlTree xmlTree;
xmlTree.load(path);
const XmlNode *particleSystemNode= xmlTree.getRootNode();
ParticleSystemType::load(particleSystemNode, dir, renderer);
//trajectory values
const XmlNode *tajectoryNode= particleSystemNode->getChild("trajectory");
trajectory= tajectoryNode->getAttribute("type")->getRestrictedValue();
//trajectory speed
const XmlNode *tajectorySpeedNode= tajectoryNode->getChild("speed");
trajectorySpeed= tajectorySpeedNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
if(trajectory=="parabolic" || trajectory=="spiral"){
//trajectory scale
const XmlNode *tajectoryScaleNode= tajectoryNode->getChild("scale");
trajectoryScale= tajectoryScaleNode->getAttribute("value")->getFloatValue();
}
else{
trajectoryScale= 1.0f;
}
if(trajectory=="spiral"){
//trajectory frequency
const XmlNode *tajectoryFrequencyNode= tajectoryNode->getChild("frequency");
trajectoryFrequency= tajectoryFrequencyNode->getAttribute("value")->getFloatValue();
}
else{
trajectoryFrequency= 1.0f;
}
}
catch(const exception &e){
throw runtime_error("Error loading ParticleSystem: "+ path + "\n" +e.what());
}
}
ProjectileParticleSystem *ParticleSystemTypeProjectile::create() {
ProjectileParticleSystem *ps= new ProjectileParticleSystem();
ParticleSystemType::setValues(ps);
ps->setTrajectory(ProjectileParticleSystem::strToTrajectory(trajectory));
ps->setTrajectorySpeed(trajectorySpeed);
ps->setTrajectoryScale(trajectoryScale);
ps->setTrajectoryFrequency(trajectoryFrequency);
return ps;
}
// ===========================================================
// class ParticleSystemTypeSplash
// ===========================================================
void ParticleSystemTypeSplash::load(const string &dir, const string &path,RendererInterface *renderer) {
try{
XmlTree xmlTree;
xmlTree.load(path);
const XmlNode *particleSystemNode= xmlTree.getRootNode();
ParticleSystemType::load(particleSystemNode, dir, renderer);
//emission rate fade
const XmlNode *emissionRateFadeNode= particleSystemNode->getChild("emission-rate-fade");
emissionRateFade= emissionRateFadeNode->getAttribute("value")->getIntValue();
//spread values
const XmlNode *verticalSpreadNode= particleSystemNode->getChild("vertical-spread");
verticalSpreadA= verticalSpreadNode->getAttribute("a")->getFloatValue(0.0f, 1.0f);
verticalSpreadB= verticalSpreadNode->getAttribute("b")->getFloatValue(-1.0f, 1.0f);
const XmlNode *horizontalSpreadNode= particleSystemNode->getChild("horizontal-spread");
horizontalSpreadA= horizontalSpreadNode->getAttribute("a")->getFloatValue(0.0f, 1.0f);
horizontalSpreadB= horizontalSpreadNode->getAttribute("b")->getFloatValue(-1.0f, 1.0f);
}
catch(const exception &e){
throw runtime_error("Error loading ParticleSystem: "+ path + "\n" +e.what());
}
}
SplashParticleSystem *ParticleSystemTypeSplash::create(){
SplashParticleSystem *ps= new SplashParticleSystem();
ParticleSystemType::setValues(ps);
ps->setEmissionRateFade(emissionRateFade);
ps->setVerticalSpreadA(verticalSpreadA);
ps->setVerticalSpreadB(verticalSpreadB);
ps->setHorizontalSpreadA(horizontalSpreadA);
ps->setHorizontalSpreadB(horizontalSpreadB);
return ps;
}
}}//end mamespace

View File

@ -0,0 +1,113 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _GLEST_GAME_PARTICLETYPE_H_
#define _GLEST_GAME_PARTICLETYPE_H_
#include <string>
#include "particle.h"
#include "factory.h"
#include "texture.h"
#include "vec.h"
#include "xml_parser.h"
#include "graphics_interface.h"
using std::string;
using namespace Shared::Graphics;
namespace Glest{ namespace Game{
using Shared::Graphics::ParticleSystem;
using Shared::Graphics::AttackParticleSystem;
using Shared::Graphics::ProjectileParticleSystem;
using Shared::Graphics::SplashParticleSystem;
using Shared::Graphics::Texture2D;
using Shared::Graphics::Vec3f;
using Shared::Graphics::Vec4f;
using Shared::Graphics::Model;
using Shared::Util::MultiFactory;
using Shared::Xml::XmlNode;
// ===========================================================
// class ParticleSystemType
//
/// A type of particle system
// ===========================================================
class ParticleSystemType{
protected:
string type;
Texture2D *texture;
Model *model;
string primitive;
Vec3f offset;
Vec4f color;
Vec4f colorNoEnergy;
float size;
float sizeNoEnergy;
float speed;
float gravity;
int emissionRate;
int energyMax;
int energyVar;
string mode;
bool teamcolorNoEnergy;
bool teamcolorEnergy;
public:
ParticleSystemType();
void load(const XmlNode *particleSystemNode, const string &dir,RendererInterface *renderer);
void setValues(AttackParticleSystem *ats);
bool hasTexture() const { return(texture != NULL); }
bool hasModel() const { return(model != NULL); }
protected:
};
// ===========================================================
// class ParticleSystemTypeProjectile
// ===========================================================
class ParticleSystemTypeProjectile: public ParticleSystemType{
private:
string trajectory;
float trajectorySpeed;
float trajectoryScale;
float trajectoryFrequency;
public:
void load(const string &dir, const string &path,RendererInterface *renderer);
ProjectileParticleSystem *create();
};
// ===========================================================
// class ParticleSystemTypeSplash
// ===========================================================
class ParticleSystemTypeSplash: public ParticleSystemType{
public:
void load(const string &dir, const string &path,RendererInterface *renderer);
SplashParticleSystem *create();
private:
int emissionRateFade;
float verticalSpreadA;
float verticalSpreadB;
float horizontalSpreadA;
float horizontalSpreadB;
};
}}//end namespace
#endif

View File

@ -412,14 +412,24 @@ void Renderer::initTexture(ResourceScope rs, Texture *texture) {
textureManager[rs]->initTexture(texture);
}
void Renderer::endTexture(ResourceScope rs, Texture **texture) {
textureManager[rs]->endTexture(texture);
void Renderer::endTexture(ResourceScope rs, Texture *texture, bool mustExistInList) {
textureManager[rs]->endTexture(texture,mustExistInList);
}
void Renderer::endLastTexture(ResourceScope rs, bool mustExistInList) {
textureManager[rs]->endLastTexture(mustExistInList);
}
Model *Renderer::newModel(ResourceScope rs){
return modelManager[rs]->newModel();
}
void Renderer::endModel(ResourceScope rs, Model *model,bool mustExistInList) {
modelManager[rs]->endModel(model,mustExistInList);
}
void Renderer::endLastModel(ResourceScope rs, bool mustExistInList) {
modelManager[rs]->endLastModel(mustExistInList);
}
Texture2D *Renderer::newTexture2D(ResourceScope rs){
return textureManager[rs]->newTexture2D();
}

View File

@ -29,6 +29,7 @@
#include <vector>
#include "model_renderer.h"
#include "model.h"
#include "graphics_interface.h"
namespace Glest{ namespace Game{
@ -54,6 +55,8 @@ using Shared::Graphics::Camera;
using Shared::Graphics::MeshCallback;
using Shared::Graphics::Mesh;
using namespace Shared::Graphics;
// =====================================================
// class MeshCallbackTeamColor
// =====================================================
@ -79,14 +82,6 @@ class ChatManager;
class Texture;
class Object;
enum ResourceScope{
rsGlobal,
rsMenu,
rsGame,
rsCount
};
// ===========================================================
// class Renderer
//
@ -161,7 +156,7 @@ public:
}
};
class Renderer {
class Renderer : public RendererInterface {
public:
//progress bar
static const int maxProgressBar;
@ -294,9 +289,13 @@ public:
//engine interface
void initTexture(ResourceScope rs, Texture *texture);
void endTexture(ResourceScope rs, Texture **texture);
void endTexture(ResourceScope rs, Texture *texture,bool mustExistInList=false);
void endLastTexture(ResourceScope rs, bool mustExistInList=false);
Model *newModel(ResourceScope rs);
void endModel(ResourceScope rs, Model *model, bool mustExistInList=false);
void endLastModel(ResourceScope rs, bool mustExistInList=false);
Texture2D *newTexture2D(ResourceScope rs);
Texture3D *newTexture3D(ResourceScope rs);
Font2D *newFont(ResourceScope rs);

View File

@ -16,6 +16,7 @@
#include "xml_parser.h"
#include "config.h"
#include "game_constants.h"
//#include "renderer.h"
#include "leak_dumper.h"
@ -32,12 +33,15 @@ UnitParticleSystemType::UnitParticleSystemType(){
texture = NULL;
}
void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, Texture2D *newTexture){
void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *renderer) {
//texture
const XmlNode *textureNode= particleSystemNode->getChild("texture");
bool textureEnabled= textureNode->getAttribute("value")->getBoolValue();
if(textureEnabled == true) {
texture = newTexture;
//Renderer &renderer= Renderer::getInstance();
texture= renderer->newTexture2D(rsGame);
//texture = newTexture;
if(textureNode->getAttribute("luminance")->getBoolValue()){
texture->setFormat(Texture::fAlpha);
texture->getPixmap()->init(1);
@ -50,8 +54,8 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin
else{
texture= NULL;
delete newTexture;
newTexture = NULL;
//delete newTexture;
//newTexture = NULL;
}
//primitive
@ -186,14 +190,14 @@ void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
ups->setBlendMode(ParticleSystem::strToBlendMode(mode));
}
void UnitParticleSystemType::load(const string &dir, const string &path, Texture2D *newTexture){
void UnitParticleSystemType::load(const string &dir, const string &path, RendererInterface *renderer){
try{
XmlTree xmlTree;
xmlTree.load(path);
const XmlNode *particleSystemNode= xmlTree.getRootNode();
UnitParticleSystemType::load(particleSystemNode, dir, newTexture);
UnitParticleSystemType::load(particleSystemNode, dir, renderer);
}
catch(const exception &e){
throw runtime_error("Error loading ParticleSystem: "+ path + "\n" +e.what());

View File

@ -19,8 +19,10 @@
#include "texture.h"
#include "vec.h"
#include "xml_parser.h"
#include "graphics_interface.h"
using std::string;
using namespace Shared::Graphics;
namespace Glest{ namespace Game{
@ -64,9 +66,10 @@ protected:
public:
UnitParticleSystemType();
void load(const XmlNode *particleSystemNode, const string &dir, Texture2D *newTexture);
void load(const string &dir, const string &path, Texture2D *newTexture);
void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture);
void load(const string &dir, const string &path, RendererInterface *newTexture);
void setValues(UnitParticleSystem *uts);
bool hasTexture() const { return(texture != NULL); }
};
}}//end namespace

View File

@ -68,8 +68,7 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c
const XmlNode *particleFileNode= particleNode->getChild("particle-file", i);
string path= particleFileNode->getAttribute("path")->getRestrictedValue();
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType();
unitParticleSystemType->load(dir, dir + "/" + path, Renderer::getInstance().newTexture2D(rsGame));
unitParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance());
unitParticleSystemTypes.push_back(unitParticleSystemType);
}
}
@ -214,7 +213,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue();
projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(dir, dir + "/" + path);
projectileParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance());
}
//proj sounds
@ -245,7 +244,7 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue();
splashParticleSystemType= new ParticleSystemTypeSplash();
splashParticleSystemType->load(dir, dir + "/" + path);
splashParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance());
}
}
}

View File

@ -223,7 +223,14 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
string path= particleFileNode->getAttribute("path")->getRestrictedValue();
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType();
unitParticleSystemType->load(dir, dir + "/" + path, Renderer::getInstance().newTexture2D(rsGame));
//Texture2D *newTexture = Renderer::getInstance().newTexture2D(rsGame);
Texture2D *newTexture = NULL;
unitParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance());
if(unitParticleSystemType->hasTexture() == false) {
//Renderer::getInstance().endLastTexture(rsGame,true);
}
damageParticleSystemTypes.push_back(unitParticleSystemType);
}
}

View File

@ -0,0 +1,68 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
#define _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
namespace Shared{ namespace Graphics{
class GraphicsFactory;
class Context;
class Texture2D;
class Model;
enum ResourceScope{
rsGlobal,
rsMenu,
rsGame,
rsCount
};
class RendererInterface {
public:
virtual Texture2D *newTexture2D(ResourceScope rs) = 0;
virtual Model *newModel(ResourceScope rs) = 0;
};
// =====================================================
// class GraphicsInterface
//
/// Interface for the graphic engine
// =====================================================
class GraphicsInterface{
private:
GraphicsFactory *graphicsFactory;
Context *currentContext;
private:
friend class TextureManager;
friend class FontManager;
private:
GraphicsInterface();
GraphicsInterface(GraphicsInterface &);
void operator=(GraphicsInterface &);
public:
static GraphicsInterface &getInstance();
void setFactory(GraphicsFactory *graphicsFactory);
void setCurrentContext(Context *context);
Context *getCurrentContext() const {return currentContext;}
GraphicsFactory *getFactory() const {return graphicsFactory;}
};
}}//end namespace
#endif

View File

@ -0,0 +1,53 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_GRAPHICS_MODELMANAGER_H_
#define _SHARED_GRAPHICS_MODELMANAGER_H_
#include "model.h"
#include <vector>
using namespace std;
namespace Shared{ namespace Graphics{
class TextureManager;
// =====================================================
// class ModelManager
// =====================================================
class ModelManager{
protected:
typedef vector<Model*> ModelContainer;
protected:
ModelContainer models;
TextureManager *textureManager;
public:
ModelManager();
virtual ~ModelManager();
Model *newModel();
void init();
void end();
void endModel(Model *model,bool mustExistInList=false);
void endLastModel(bool mustExistInList=false);
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
};
}}//end namespace
#endif

View File

@ -44,7 +44,8 @@ public:
void setFilter(Texture::Filter textureFilter);
void setMaxAnisotropy(int maxAnisotropy);
void initTexture(Texture *texture);
void endTexture(Texture **texture);
void endTexture(Texture *texture,bool mustExistInList=false);
void endLastTexture(bool mustExistInList=false);
void reinitTextures();
Texture *getTexture(const string &path);

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -181,7 +181,7 @@ void Texture1DGl::end(){
void Texture2DGl::init(Filter filter, int maxAnisotropy){
assertGl();
if(!inited){
if(!inited) {
//params
GLint wrap= toWrapModeGl(wrapMode);
@ -219,7 +219,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
if(error!=0){
//throw runtime_error("Error building texture 2D mipmaps");
char szBuf[1024]="";
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH());
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d",error,(pixmap.getPath() != "" ? pixmap.getPath().c_str() : this->path.c_str()),pixmap.getW(),pixmap.getH());
throw runtime_error(szBuf);
}
}

View File

@ -0,0 +1,98 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "model_manager.h"
#include "graphics_interface.h"
#include "graphics_factory.h"
#include <cstdlib>
#include <stdexcept>
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{
// =====================================================
// class ModelManager
// =====================================================
ModelManager::ModelManager(){
textureManager= NULL;
}
ModelManager::~ModelManager(){
end();
}
Model *ModelManager::newModel(){
Model *model= GraphicsInterface::getInstance().getFactory()->newModel();
model->setTextureManager(textureManager);
models.push_back(model);
return model;
}
void ModelManager::init(){
for(size_t i=0; i<models.size(); ++i){
if(models[i] != NULL) {
models[i]->init();
}
}
}
void ModelManager::end(){
for(size_t i=0; i<models.size(); ++i){
if(models[i] != NULL) {
models[i]->end();
delete models[i];
}
}
models.clear();
}
void ModelManager::endModel(Model *model,bool mustExistInList) {
if(model != NULL) {
bool found = false;
for(int idx = 0; idx < models.size(); idx++) {
Model *curModel = models[idx];
if(curModel == model) {
found = true;
models.erase(models.begin() + idx);
break;
}
}
if(found == false && mustExistInList == true) {
throw std::runtime_error("found == false in endModel");
}
model->end();
delete model;
}
}
void ModelManager::endLastModel(bool mustExistInList) {
bool found = false;
if(models.size() > 0) {
found = true;
int index = models.size()-1;
Model *curModel = models[index];
models.erase(models.begin() + index);
curModel->end();
delete curModel;
}
if(found == false && mustExistInList == true) {
throw std::runtime_error("found == false in endLastModel");
}
}
}}//end namespace

View File

@ -357,8 +357,6 @@ Pixmap1D::~Pixmap1D(){
}
void Pixmap1D::load(const string &path){
this->path = path;
string extension= path.substr(path.find_last_of('.')+1);
if(extension=="bmp"){
loadBmp(path);
@ -369,6 +367,7 @@ void Pixmap1D::load(const string &path){
else{
throw runtime_error("Unknown pixmap extension: "+extension);
}
this->path = path;
}
void Pixmap1D::loadBmp(const string &path){
@ -477,8 +476,8 @@ Pixmap2D* Pixmap2D::loadPath(const string& path) {
}
void Pixmap2D::load(const string &path){
this->path = path;
FileReader<Pixmap2D>::readPath(path,this);
this->path = path;
}
@ -781,8 +780,6 @@ Pixmap3D::~Pixmap3D(){
}
void Pixmap3D::loadSlice(const string &path, int slice){
this->path = path;
string extension= path.substr(path.find_last_of('.')+1);
if(extension=="bmp"){
loadSliceBmp(path, slice);
@ -793,6 +790,7 @@ void Pixmap3D::loadSlice(const string &path, int slice){
else{
throw runtime_error("Unknown pixmap extension: "+extension);
}
this->path = path;
}
void Pixmap3D::loadSliceBmp(const string &path, int slice){

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -46,6 +46,7 @@ void Texture1D::load(const string &path){
pixmap.init(defaultComponents);
}
pixmap.load(path);
this->path= path;
}
// =====================================================
@ -60,6 +61,7 @@ void Texture2D::load(const string &path){
pixmap.init(defaultComponents);
}
pixmap.load(path);
this->path= path;
}
// =====================================================
@ -74,6 +76,7 @@ void Texture3D::loadSlice(const string &path, int slice){
pixmap.init(defaultComponents);
}
pixmap.loadSlice(path, slice);
this->path= path;
}
// =====================================================
@ -88,6 +91,7 @@ void TextureCube::loadFace(const string &path, int face){
pixmap.init(defaultComponents);
}
pixmap.loadFace(path, face);
this->path= path;
}
}}//end namespace

View File

@ -40,11 +40,38 @@ void TextureManager::initTexture(Texture *texture) {
}
}
void TextureManager::endTexture(Texture **texture) {
if(texture != NULL && *texture != NULL) {
(*texture)->end();
delete (*texture);
*texture = NULL;
void TextureManager::endTexture(Texture *texture,bool mustExistInList) {
if(texture != NULL) {
bool found = false;
for(int idx = 0; idx < textures.size(); idx++) {
Texture *curTexture = textures[idx];
if(curTexture == texture) {
found = true;
textures.erase(textures.begin() + idx);
break;
}
}
if(found == false && mustExistInList == true) {
throw std::runtime_error("found == false in endTexture");
}
texture->end();
delete texture;
}
}
void TextureManager::endLastTexture(bool mustExistInList) {
bool found = false;
if(textures.size() > 0) {
found = true;
int index = textures.size()-1;
Texture *curTexture = textures[index];
textures.erase(textures.begin() + index);
curTexture->end();
delete curTexture;
}
if(found == false && mustExistInList == true) {
throw std::runtime_error("found == false in endLastTexture");
}
}
@ -63,8 +90,10 @@ void TextureManager::init(bool forceInit) {
void TextureManager::end(){
for(int i=0; i<textures.size(); ++i){
textures[i]->end();
delete textures[i];
if(textures[i] != NULL) {
textures[i]->end();
delete textures[i];
}
}
textures.clear();
}