mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 13:23:59 +02:00
- added some initial work to support FBO (frame buffer objects)
- added many NULL check guards throughout the code - added a safe mutex around ptr access of background thread on custom menu
This commit is contained in:
@@ -413,8 +413,10 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos);
|
canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos);
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
localCacheForUnitCellMovement[node->pos][sucPos] = canUnitMoveToCell;
|
localCacheForUnitCellMovement[node->pos][sucPos] = canUnitMoveToCell;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(openPos(sucPos) == false && canUnitMoveToCell == true) {
|
if(openPos(sucPos) == false && canUnitMoveToCell == true) {
|
||||||
//if node is not open and canMove then generate another node
|
//if node is not open and canMove then generate another node
|
||||||
|
@@ -50,6 +50,9 @@ GameCamera::GameCamera() : pos(0.f, defaultHeight, 0.f),
|
|||||||
|
|
||||||
cacheVisibleQuad.clear();
|
cacheVisibleQuad.clear();
|
||||||
MaxVisibleQuadItemCache = config.getInt("MaxVisibleQuadItemCache",intToStr(-1).c_str());
|
MaxVisibleQuadItemCache = config.getInt("MaxVisibleQuadItemCache",intToStr(-1).c_str());
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == true) {
|
||||||
|
MaxVisibleQuadItemCache = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//config
|
//config
|
||||||
speed= 15.f / GameConstants::cameraFps;
|
speed= 15.f / GameConstants::cameraFps;
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
using namespace Shared::Graphics;
|
using namespace Shared::Graphics;
|
||||||
using namespace Shared::Graphics::Gl;
|
using namespace Shared::Graphics::Gl;
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
|
using namespace Shared::Graphics;
|
||||||
|
|
||||||
namespace Glest { namespace Game{
|
namespace Glest { namespace Game{
|
||||||
|
|
||||||
@@ -2960,7 +2961,7 @@ void Renderer::clearZBuffer(){
|
|||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::loadConfig(){
|
void Renderer::loadConfig() {
|
||||||
Config &config= Config::getInstance();
|
Config &config= Config::getInstance();
|
||||||
|
|
||||||
//cache most used config params
|
//cache most used config params
|
||||||
@@ -2986,6 +2987,36 @@ void Renderer::loadConfig(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Texture2D *Renderer::saveScreenToTexture(int x, int y, int width, int height) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
Config &config= Config::getInstance();
|
||||||
|
Texture2D::Filter textureFilter = strToTextureFilter(config.getString("Filter"));
|
||||||
|
int maxAnisotropy = config.getInt("FilterMaxAnisotropy");
|
||||||
|
|
||||||
|
Texture2D *texture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
||||||
|
//texture->setFormat(Texture::fRgba);
|
||||||
|
texture->setForceCompressionDisabled(true);
|
||||||
|
texture->setMipmap(false);
|
||||||
|
//Pixmap2D *pixmapScreenShot = new Pixmap2D(width, height, 3);
|
||||||
|
Pixmap2D *pixmapScreenShot = texture->getPixmap();
|
||||||
|
pixmapScreenShot->init(width, height, 3);
|
||||||
|
//const Metrics &sm= Metrics::getInstance();
|
||||||
|
//pixmapScreenShot->init(sm.getScreenW(), sm.getScreenH(), 3);
|
||||||
|
texture->init(textureFilter,maxAnisotropy);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
//glFinish();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
glReadPixels(x, y, pixmapScreenShot->getW(), pixmapScreenShot->getH(),
|
||||||
|
GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::saveScreen(const string &path) {
|
void Renderer::saveScreen(const string &path) {
|
||||||
const Metrics &sm= Metrics::getInstance();
|
const Metrics &sm= Metrics::getInstance();
|
||||||
|
|
||||||
@@ -3834,6 +3865,14 @@ void Renderer::renderTile(const Vec2i &pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderQuad(int x, int y, int w, int h, const Texture2D *texture) {
|
void Renderer::renderQuad(int x, int y, int w, int h, const Texture2D *texture) {
|
||||||
|
|
||||||
|
if(w < 0) {
|
||||||
|
w = texture->getPixmap()->getW();
|
||||||
|
}
|
||||||
|
if(h < 0) {
|
||||||
|
h = texture->getPixmap()->getH();
|
||||||
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(texture)->getHandle());
|
glBindTexture(GL_TEXTURE_2D, static_cast<const Texture2DGl*>(texture)->getHandle());
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
glTexCoord2i(0, 1);
|
glTexCoord2i(0, 1);
|
||||||
@@ -4055,7 +4094,8 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
||||||
int screenPosX, int screenPosY) {
|
int screenPosX, int screenPosY,
|
||||||
|
Texture2D **renderToTexture) {
|
||||||
float alt=0;
|
float alt=0;
|
||||||
float showWater=0;
|
float showWater=0;
|
||||||
int renderMapHeight=64;
|
int renderMapHeight=64;
|
||||||
@@ -4077,23 +4117,75 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(renderToTexture != NULL) {
|
||||||
|
Config &config= Config::getInstance();
|
||||||
|
Texture2D::Filter textureFilter = strToTextureFilter(config.getString("Filter"));
|
||||||
|
int maxAnisotropy = config.getInt("FilterMaxAnisotropy");
|
||||||
|
|
||||||
|
*renderToTexture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
|
||||||
|
Texture2DGl *texture = static_cast<Texture2DGl *>(*renderToTexture);
|
||||||
|
//texture->setFormat(Texture::fAlpha);
|
||||||
|
texture->setMipmap(false);
|
||||||
|
Pixmap2D *pixmapScreenShot = texture->getPixmap();
|
||||||
|
pixmapScreenShot->init(metrics.getVirtualW(), metrics.getVirtualH(), 3);
|
||||||
|
//pixmapScreenShot->init(map->getW(),map->getH(),3);
|
||||||
|
//pixmapScreenShot->init(200, 360, 3);
|
||||||
|
texture->setForceCompressionDisabled(true);
|
||||||
|
texture->init(textureFilter,maxAnisotropy);
|
||||||
|
|
||||||
|
|
||||||
|
//texture->initFrameBuffer();
|
||||||
|
//texture->attachFrameBufferToTexture();
|
||||||
|
|
||||||
|
//texture->initRenderBuffer();
|
||||||
|
//texture->attachRenderBuffer();
|
||||||
|
|
||||||
|
texture->setup_FBO_RBO();
|
||||||
|
|
||||||
|
if(texture->checkFrameBufferStatus() == false) {
|
||||||
|
//printf("******************** WARNING CANNOT Attach to FBO!\n");
|
||||||
|
texture->end();
|
||||||
|
delete texture;
|
||||||
|
*renderToTexture=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
glFrontFace(GL_CW);
|
glFrontFace(GL_CW);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
//glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
// glViewport(screenPosX, screenPosY, sizeH,sizeW);
|
//glViewport(screenPosX, screenPosY, metrics.getVirtualW(),metrics.getVirtualH());
|
||||||
// glOrtho(0, clientW, 0, clientH, -1, 1);
|
// glOrtho(0, clientW, 0, clientH, -1, 1);
|
||||||
|
|
||||||
|
//glOrtho(screenPosX, screenPosX+clientW, screenPosY+clientH, screenPosY, 0, 1);
|
||||||
glOrtho(0, metrics.getVirtualW(), 0, metrics.getVirtualH(), 0, 1);
|
glOrtho(0, metrics.getVirtualW(), 0, metrics.getVirtualH(), 0, 1);
|
||||||
|
//gluOrtho2D (0, metrics.getVirtualW(), 0, metrics.getVirtualH());
|
||||||
|
|
||||||
|
//glEnable( GL_SCISSOR_TEST );
|
||||||
|
//glScissor(screenPosX, screenPosY,metrics.getVirtualW(), metrics.getVirtualH());
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
glTranslatef(static_cast<float>(screenPosX),static_cast<float>(screenPosY)-clientH,0.0f);
|
glTranslatef(static_cast<float>(screenPosX),static_cast<float>(screenPosY)-clientH,0.0f);
|
||||||
|
|
||||||
|
//glEnable( GL_SCISSOR_TEST );
|
||||||
|
//glScissor(screenPosX, screenPosY,screenPosX-clientW, screenPosY-clientH);
|
||||||
|
|
||||||
|
//int newX = screenPosX - (metrics.getVirtualW() / 2);
|
||||||
|
//int newY = screenPosY - (metrics.getVirtualH() / 2);
|
||||||
|
//int newX = 0;
|
||||||
|
//int newY = 0;
|
||||||
|
//glTranslatef(static_cast<float>(newX),static_cast<float>(newY),0.0f);
|
||||||
|
|
||||||
glPushAttrib(GL_CURRENT_BIT);
|
glPushAttrib(GL_CURRENT_BIT);
|
||||||
//glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
|
//glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
|
||||||
glLineWidth(1);
|
glLineWidth(1);
|
||||||
@@ -4108,11 +4200,21 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
showWater = (showWater > 0)? showWater:0;
|
showWater = (showWater > 0)? showWater:0;
|
||||||
Vec3f surfColor;
|
Vec3f surfColor;
|
||||||
switch (map->getSurface(i, j)) {
|
switch (map->getSurface(i, j)) {
|
||||||
case st_Grass: surfColor = Vec3f(0.0, 0.8f * alt, 0.f + showWater); break;
|
case st_Grass:
|
||||||
case st_Secondary_Grass: surfColor = Vec3f(0.4f * alt, 0.6f * alt, 0.f + showWater); break;
|
surfColor = Vec3f(0.0, 0.8f * alt, 0.f + showWater);
|
||||||
case st_Road: surfColor = Vec3f(0.6f * alt, 0.3f * alt, 0.f + showWater); break;
|
break;
|
||||||
case st_Stone: surfColor = Vec3f(0.7f * alt, 0.7f * alt, 0.7f * alt + showWater); break;
|
case st_Secondary_Grass:
|
||||||
case st_Ground: surfColor = Vec3f(0.7f * alt, 0.5f * alt, 0.3f * alt + showWater); break;
|
surfColor = Vec3f(0.4f * alt, 0.6f * alt, 0.f + showWater);
|
||||||
|
break;
|
||||||
|
case st_Road:
|
||||||
|
surfColor = Vec3f(0.6f * alt, 0.3f * alt, 0.f + showWater);
|
||||||
|
break;
|
||||||
|
case st_Stone:
|
||||||
|
surfColor = Vec3f(0.7f * alt, 0.7f * alt, 0.7f * alt + showWater);
|
||||||
|
break;
|
||||||
|
case st_Ground:
|
||||||
|
surfColor = Vec3f(0.7f * alt, 0.5f * alt, 0.3f * alt + showWater);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
glColor3fv(surfColor.ptr());
|
glColor3fv(surfColor.ptr());
|
||||||
@@ -4127,20 +4229,42 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
//objects
|
//objects
|
||||||
if(renderAll == true) {
|
if(renderAll == true) {
|
||||||
switch (map->getObject(i, j)) {
|
switch (map->getObject(i, j)) {
|
||||||
case 0: glColor3f(0.f, 0.f, 0.f); break;
|
case 0:
|
||||||
case 1: glColor3f(1.f, 0.f, 0.f); break;
|
glColor3f(0.f, 0.f, 0.f);
|
||||||
case 2: glColor3f(1.f, 1.f, 1.f); break;
|
break;
|
||||||
case 3: glColor3f(0.5f, 0.5f, 1.f); break;
|
case 1:
|
||||||
case 4: glColor3f(0.f, 0.f, 1.f); break;
|
glColor3f(1.f, 0.f, 0.f);
|
||||||
case 5: glColor3f(0.5f, 0.5f, 0.5f); break;
|
break;
|
||||||
case 6: glColor3f(1.f, 0.8f, 0.5f); break;
|
case 2:
|
||||||
case 7: glColor3f(0.f, 1.f, 1.f); break;
|
glColor3f(1.f, 1.f, 1.f);
|
||||||
case 8: glColor3f(0.7f, 0.1f, 0.3f); break;
|
break;
|
||||||
case 9: glColor3f(0.5f, 1.f, 0.1f); break;
|
case 3:
|
||||||
case 10: glColor3f(1.f, 0.2f, 0.8f); break;// we don't render unvisible blocking objects
|
glColor3f(0.5f, 0.5f, 1.f);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
glColor3f(0.f, 0.f, 1.f);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
glColor3f(0.5f, 0.5f, 0.5f);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
glColor3f(1.f, 0.8f, 0.5f);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
glColor3f(0.f, 1.f, 1.f);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
glColor3f(0.7f, 0.1f, 0.3f);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
glColor3f(0.5f, 1.f, 0.1f);
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
glColor3f(1.f, 0.2f, 0.8f);
|
||||||
|
break;// we don't render unvisible blocking objects
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( renderAll && (map->getObject(i, j) != 0) && (map->getObject(i, j) != 10) ){
|
if ( renderAll && (map->getObject(i, j) != 0) && (map->getObject(i, j) != 10) ) {
|
||||||
glPointSize(cellSize / 2.f);
|
glPointSize(cellSize / 2.f);
|
||||||
glBegin(GL_POINTS);
|
glBegin(GL_POINTS);
|
||||||
glVertex2f(i * cellSize + cellSize / 2.f, clientH - j * cellSize - cellSize / 2.f);
|
glVertex2f(i * cellSize + cellSize / 2.f, clientH - j * cellSize - cellSize / 2.f);
|
||||||
@@ -4211,15 +4335,16 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//start locations
|
//start locations
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
// force playerCrossSize to be at least of size 4
|
// force playerCrossSize to be at least of size 4
|
||||||
if(cellSize<4)
|
if(cellSize < 4) {
|
||||||
playerCrossSize=4;
|
playerCrossSize = 4;
|
||||||
else
|
}
|
||||||
playerCrossSize=cellSize;
|
else {
|
||||||
|
playerCrossSize = cellSize;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < map->getMaxFactions(); i++) {
|
for (int i = 0; i < map->getMaxFactions(); i++) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
@@ -4245,8 +4370,29 @@ void Renderer::renderMapPreview( const MapPreview *map, bool renderAll,
|
|||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
//glDisable( GL_SCISSOR_TEST );
|
||||||
//glViewport(0, 0, 0, 0);
|
//glViewport(0, 0, 0, 0);
|
||||||
|
|
||||||
|
if(renderToTexture != NULL) {
|
||||||
|
|
||||||
|
//*renderToTexture = saveScreenToTexture(screenPosX, screenPosY, metrics.getVirtualW(), metrics.getVirtualH());
|
||||||
|
//*renderToTexture = saveScreenToTexture(0, 0, metrics.getVirtualW(), metrics.getVirtualH());
|
||||||
|
/*
|
||||||
|
Texture2DGl *texture = static_cast<Texture2DGl *>(*renderToTexture);
|
||||||
|
if(texture != NULL) {
|
||||||
|
//*renderToTexture = saveScreenToTexture(screenPosX, screenPosY, clientW, clientH);
|
||||||
|
texture->dettachFrameBufferFromTexture();
|
||||||
|
|
||||||
|
// Signal the threads queue to add a screenshot save request
|
||||||
|
//MutexSafeWrapper safeMutex(&saveScreenShotThreadAccessor);
|
||||||
|
//saveScreenQueue.push_back(make_pair("bob.png",texture->getPixmap()));
|
||||||
|
//*renderToTexture=NULL;
|
||||||
|
//safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
//texture->teardown_FBO_RBO();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -339,7 +339,7 @@ public:
|
|||||||
void renderMinimap();
|
void renderMinimap();
|
||||||
void renderDisplay();
|
void renderDisplay();
|
||||||
void renderMenuBackground(const MenuBackground *menuBackground);
|
void renderMenuBackground(const MenuBackground *menuBackground);
|
||||||
void renderMapPreview(const MapPreview *map, bool renderAll, int screenX, int screenY);
|
void renderMapPreview(const MapPreview *map, bool renderAll, int screenX, int screenY,Texture2D **renderToTexture=NULL);
|
||||||
|
|
||||||
//computing
|
//computing
|
||||||
bool computePosition(const Vec2i &screenPos, Vec2i &worldPos);
|
bool computePosition(const Vec2i &screenPos, Vec2i &worldPos);
|
||||||
@@ -392,6 +392,8 @@ public:
|
|||||||
uint64 getCurrentPixelByteCount(ResourceScope rs=rsGame) const;
|
uint64 getCurrentPixelByteCount(ResourceScope rs=rsGame) const;
|
||||||
unsigned int getSaveScreenQueueSize();
|
unsigned int getSaveScreenQueueSize();
|
||||||
|
|
||||||
|
Texture2D *saveScreenToTexture(int x, int y, int width, int height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//private misc
|
//private misc
|
||||||
float computeSunAngle(float time);
|
float computeSunAngle(float time);
|
||||||
|
@@ -59,6 +59,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
factionTexture=NULL;
|
factionTexture=NULL;
|
||||||
currentTechName_factionPreview="";
|
currentTechName_factionPreview="";
|
||||||
currentFactionName_factionPreview="";
|
currentFactionName_factionPreview="";
|
||||||
|
mapPreviewTexture=NULL;
|
||||||
|
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
@@ -487,6 +488,9 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
|
|
||||||
GraphicComponent::applyAllCustomProperties(containerName);
|
GraphicComponent::applyAllCustomProperties(containerName);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
|
||||||
|
publishToMasterserverThreadInDeletion = false;
|
||||||
|
|
||||||
publishToMasterserverThread = new SimpleTaskThread(this,0,25);
|
publishToMasterserverThread = new SimpleTaskThread(this,0,25);
|
||||||
publishToMasterserverThread->setUniqueID(__FILE__);
|
publishToMasterserverThread->setUniqueID(__FILE__);
|
||||||
publishToMasterserverThread->start();
|
publishToMasterserverThread->start();
|
||||||
@@ -497,16 +501,28 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
MenuStateCustomGame::~MenuStateCustomGame() {
|
MenuStateCustomGame::~MenuStateCustomGame() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
if(publishToMasterserverThreadInDeletion == false) {
|
||||||
|
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
|
||||||
|
|
||||||
|
if(publishToMasterserverThread != NULL) {
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
|
|
||||||
//BaseThread::shutdownAndWait(publishToMasterserverThread);
|
//BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
|
publishToMasterserverThreadInDeletion = false;
|
||||||
|
safeMutexPtr.ReleaseLock();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
safeMutexPtr.ReleaseLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
cleanupFactionTexture();
|
cleanupFactionTexture();
|
||||||
|
cleanupMapPreviewTexture();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
@@ -514,6 +530,9 @@ MenuStateCustomGame::~MenuStateCustomGame() {
|
|||||||
void MenuStateCustomGame::returnToParentMenu(){
|
void MenuStateCustomGame::returnToParentMenu(){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
|
||||||
|
publishToMasterserverThreadInDeletion = true;
|
||||||
|
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
bool returnToMasterServerMenu = parentMenuIsMs;
|
bool returnToMasterServerMenu = parentMenuIsMs;
|
||||||
@@ -521,6 +540,8 @@ void MenuStateCustomGame::returnToParentMenu(){
|
|||||||
//BaseThread::shutdownAndWait(publishToMasterserverThread);
|
//BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
|
publishToMasterserverThreadInDeletion = false;
|
||||||
|
safeMutexPtr.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
@@ -563,9 +584,13 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
|
||||||
|
publishToMasterserverThreadInDeletion = true;
|
||||||
//BaseThread::shutdownAndWait(publishToMasterserverThread);
|
//BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
|
publishToMasterserverThreadInDeletion = false;
|
||||||
|
safeMutexPtr.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
@@ -1024,8 +1049,13 @@ void MenuStateCustomGame::PlayNow() {
|
|||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
|
||||||
|
publishToMasterserverThreadInDeletion = true;
|
||||||
|
//BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
|
publishToMasterserverThreadInDeletion = false;
|
||||||
|
safeMutexPtr.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
@@ -1090,7 +1120,12 @@ void MenuStateCustomGame::render() {
|
|||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
if(factionTexture != NULL) {
|
if(factionTexture != NULL) {
|
||||||
renderer.renderTextureQuad(800,600,200,150,factionTexture,1);
|
renderer.renderTextureQuad(800,600,200,150,factionTexture,0.7);
|
||||||
|
}
|
||||||
|
if(mapPreviewTexture != NULL) {
|
||||||
|
//renderer.renderTextureQuad(10,350,-1,-1,mapPreviewTexture,0.7);
|
||||||
|
renderer.renderTextureQuad(800,300,200,150,mapPreviewTexture,0.7);
|
||||||
|
//printf("=================> Rendering map preview texture\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mainMessageBox.getEnabled()){
|
if(mainMessageBox.getEnabled()){
|
||||||
@@ -1179,7 +1214,8 @@ void MenuStateCustomGame::render() {
|
|||||||
|
|
||||||
if(program != NULL) program->renderProgramMsgBox();
|
if(program != NULL) program->renderProgramMsgBox();
|
||||||
|
|
||||||
if(enableMapPreview && (mapPreview.hasFileLoaded() == true)) {
|
if( enableMapPreview == true &&
|
||||||
|
mapPreview.hasFileLoaded() == true) {
|
||||||
|
|
||||||
int mouseX = mainMenu->getMouseX();
|
int mouseX = mainMenu->getMouseX();
|
||||||
int mouseY = mainMenu->getMouseY();
|
int mouseY = mainMenu->getMouseY();
|
||||||
@@ -1187,8 +1223,16 @@ void MenuStateCustomGame::render() {
|
|||||||
|
|
||||||
renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim);
|
renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim);
|
||||||
bool renderAll = (listBoxFogOfWar.getSelectedItemIndex() == 1);
|
bool renderAll = (listBoxFogOfWar.getSelectedItemIndex() == 1);
|
||||||
|
|
||||||
|
if(mapPreviewTexture == NULL) {
|
||||||
|
//printf("=================> Rendering map preview into a texture BEFORE (%p)\n", mapPreviewTexture);
|
||||||
|
renderer.renderMapPreview(&mapPreview, renderAll, 10, 350,&mapPreviewTexture);
|
||||||
|
//printf("=================> Rendering map preview into a texture AFTER (%p)\n", mapPreviewTexture);
|
||||||
|
}
|
||||||
|
else {
|
||||||
renderer.renderMapPreview(&mapPreview, renderAll, 10, 350);
|
renderer.renderMapPreview(&mapPreview, renderAll, 10, 350);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderer.renderChatManager(&chatManager);
|
renderer.renderChatManager(&chatManager);
|
||||||
renderer.renderConsole(&console,showFullConsole,true);
|
renderer.renderConsole(&console,showFullConsole,true);
|
||||||
@@ -2214,6 +2258,9 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa
|
|||||||
if(loadMapPreview == true) {
|
if(loadMapPreview == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
mapPreview.loadFromFile(file.c_str());
|
mapPreview.loadFromFile(file.c_str());
|
||||||
|
|
||||||
|
//printf("Loading map preview MAP\n");
|
||||||
|
cleanupMapPreviewTexture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(exception &e) {
|
catch(exception &e) {
|
||||||
@@ -2625,4 +2672,21 @@ void MenuStateCustomGame::cleanupFactionTexture() {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuStateCustomGame::cleanupMapPreviewTexture() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
//printf("CLEANUP map preview texture\n");
|
||||||
|
|
||||||
|
if(mapPreviewTexture != NULL) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
mapPreviewTexture->end();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
delete mapPreviewTexture;
|
||||||
|
mapPreviewTexture = NULL;
|
||||||
|
}
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -101,6 +101,8 @@ private:
|
|||||||
std::map<string,string> publishToServerInfo;
|
std::map<string,string> publishToServerInfo;
|
||||||
SimpleTaskThread *publishToMasterserverThread;
|
SimpleTaskThread *publishToMasterserverThread;
|
||||||
Mutex masterServerThreadAccessor;
|
Mutex masterServerThreadAccessor;
|
||||||
|
Mutex publishToMasterserverThreadPtrChangeAccessor;
|
||||||
|
bool publishToMasterserverThreadInDeletion;
|
||||||
|
|
||||||
bool parentMenuIsMs;
|
bool parentMenuIsMs;
|
||||||
int soundConnectionCount;
|
int soundConnectionCount;
|
||||||
@@ -132,6 +134,8 @@ private:
|
|||||||
Texture2D *factionTexture;
|
Texture2D *factionTexture;
|
||||||
|
|
||||||
MapPreview mapPreview;
|
MapPreview mapPreview;
|
||||||
|
Texture2D *mapPreviewTexture;
|
||||||
|
|
||||||
bool autostart;
|
bool autostart;
|
||||||
std::map<int,int> lastSelectedTeamIndex;
|
std::map<int,int> lastSelectedTeamIndex;
|
||||||
|
|
||||||
@@ -157,6 +161,8 @@ private:
|
|||||||
bool hasNetworkGameSettings();
|
bool hasNetworkGameSettings();
|
||||||
void loadGameSettings(GameSettings *gameSettings);
|
void loadGameSettings(GameSettings *gameSettings);
|
||||||
void loadMapInfo(string file, MapInfo *mapInfo,bool loadMapPreview);
|
void loadMapInfo(string file, MapInfo *mapInfo,bool loadMapPreview);
|
||||||
|
void cleanupMapPreviewTexture();
|
||||||
|
|
||||||
void reloadFactions(bool keepExistingSelectedItem);
|
void reloadFactions(bool keepExistingSelectedItem);
|
||||||
void updateControlers();
|
void updateControlers();
|
||||||
void closeUnusedSlots();
|
void closeUnusedSlots();
|
||||||
|
@@ -20,8 +20,9 @@
|
|||||||
#include "sound_renderer.h"
|
#include "sound_renderer.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "tech_tree.h"
|
#include "tech_tree.h"
|
||||||
#include "leak_dumper.h"
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
|
|
||||||
@@ -672,6 +673,7 @@ void Faction::resetResourceAmount(const ResourceType *rt){
|
|||||||
|
|
||||||
bool Faction::isResourceTargetInCache(const Vec2i &pos, bool incrementUseCounter) {
|
bool Faction::isResourceTargetInCache(const Vec2i &pos, bool incrementUseCounter) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
if(cacheResourceTargetList.size() > 0) {
|
if(cacheResourceTargetList.size() > 0) {
|
||||||
std::map<Vec2i,int>::iterator iter = cacheResourceTargetList.find(pos);
|
std::map<Vec2i,int>::iterator iter = cacheResourceTargetList.find(pos);
|
||||||
result = (iter != cacheResourceTargetList.end());
|
result = (iter != cacheResourceTargetList.end());
|
||||||
@@ -679,27 +681,32 @@ bool Faction::isResourceTargetInCache(const Vec2i &pos, bool incrementUseCounter
|
|||||||
iter->second++;
|
iter->second++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faction::addResourceTargetToCache(const Vec2i &pos) {
|
void Faction::addResourceTargetToCache(const Vec2i &pos) {
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
bool duplicateEntry = isResourceTargetInCache(pos,true);
|
bool duplicateEntry = isResourceTargetInCache(pos,true);
|
||||||
if(duplicateEntry == false) {
|
if(duplicateEntry == false) {
|
||||||
cacheResourceTargetList[pos] = 1;
|
cacheResourceTargetList[pos] = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faction::removeResourceTargetFromCache(const Vec2i &pos) {
|
void Faction::removeResourceTargetFromCache(const Vec2i &pos) {
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
if(cacheResourceTargetList.size() > 0) {
|
if(cacheResourceTargetList.size() > 0) {
|
||||||
std::map<Vec2i,int>::iterator iter = cacheResourceTargetList.find(pos);
|
std::map<Vec2i,int>::iterator iter = cacheResourceTargetList.find(pos);
|
||||||
if(iter != cacheResourceTargetList.end()) {
|
if(iter != cacheResourceTargetList.end()) {
|
||||||
cacheResourceTargetList.erase(pos);
|
cacheResourceTargetList.erase(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faction::addCloseResourceTargetToCache(const Vec2i &pos) {
|
void Faction::addCloseResourceTargetToCache(const Vec2i &pos) {
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
if(cachedCloseResourceTargetLookupList.find(pos) == cachedCloseResourceTargetLookupList.end()) {
|
if(cachedCloseResourceTargetLookupList.find(pos) == cachedCloseResourceTargetLookupList.end()) {
|
||||||
const Map *map = world->getMap();
|
const Map *map = world->getMap();
|
||||||
const int harvestDistance = 5;
|
const int harvestDistance = 5;
|
||||||
@@ -720,10 +727,12 @@ void Faction::addCloseResourceTargetToCache(const Vec2i &pos) {
|
|||||||
|
|
||||||
cachedCloseResourceTargetLookupList[pos] = true;
|
cachedCloseResourceTargetLookupList[pos] = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type) {
|
Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type) {
|
||||||
Vec2i result(-1);
|
Vec2i result(-1);
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
if(cacheResourceTargetList.size() > 0) {
|
if(cacheResourceTargetList.size() > 0) {
|
||||||
std::vector<Vec2i> deleteList;
|
std::vector<Vec2i> deleteList;
|
||||||
|
|
||||||
@@ -793,11 +802,12 @@ Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceT
|
|||||||
cleanupResourceTypeTargetCache(&deleteList);
|
cleanupResourceTypeTargetCache(&deleteList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faction::cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr) {
|
void Faction::cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr) {
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
if(cacheResourceTargetList.size() > 0) {
|
if(cacheResourceTargetList.size() > 0) {
|
||||||
if(deleteListPtr != NULL || difftime(time(NULL),lastResourceTargettListPurge) >= 120) {
|
if(deleteListPtr != NULL || difftime(time(NULL),lastResourceTargettListPurge) >= 120) {
|
||||||
lastResourceTargettListPurge = time(NULL);
|
lastResourceTargettListPurge = time(NULL);
|
||||||
@@ -828,10 +838,12 @@ void Faction::cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Vec2i> Faction::findCachedPath(const Vec2i &target, Unit *unit) {
|
std::vector<Vec2i> Faction::findCachedPath(const Vec2i &target, Unit *unit) {
|
||||||
std::vector<Vec2i> result;
|
std::vector<Vec2i> result;
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||||
// Lets find the shortest and most successful path already taken by a
|
// Lets find the shortest and most successful path already taken by a
|
||||||
// similar sized unit
|
// similar sized unit
|
||||||
@@ -872,10 +884,12 @@ std::vector<Vec2i> Faction::findCachedPath(const Vec2i &target, Unit *unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faction::addCachedPath(const Vec2i &target, Unit *unit) {
|
void Faction::addCachedPath(const Vec2i &target, Unit *unit) {
|
||||||
|
if(Config::getInstance().getBool("DisableCaching","false") == false) {
|
||||||
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
if(successfulPathFinderTargetList.find(target) == successfulPathFinderTargetList.end()) {
|
||||||
FactionPathSuccessCache cache;
|
FactionPathSuccessCache cache;
|
||||||
cache.unitSize = unit->getType()->getSize();
|
cache.unitSize = unit->getType()->getSize();
|
||||||
@@ -927,6 +941,7 @@ void Faction::addCachedPath(const Vec2i &target, Unit *unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Faction::deletePixels() {
|
void Faction::deletePixels() {
|
||||||
|
@@ -50,7 +50,6 @@ Object::~Object(){
|
|||||||
delete resource;
|
delete resource;
|
||||||
|
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
//renderer.setQuadCacheDirty(true);
|
|
||||||
renderer.removeObjectFromQuadCache(this);
|
renderer.removeObjectFromQuadCache(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -296,7 +296,6 @@ Unit::~Unit(){
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
//renderer.setQuadCacheDirty(true);
|
|
||||||
renderer.removeUnitFromQuadCache(this);
|
renderer.removeUnitFromQuadCache(this);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
@@ -106,8 +106,53 @@ Map::~Map(){
|
|||||||
Logger::getInstance().add("Cells", true);
|
Logger::getInstance().add("Cells", true);
|
||||||
|
|
||||||
delete [] cells;
|
delete [] cells;
|
||||||
|
cells = NULL;
|
||||||
delete [] surfaceCells;
|
delete [] surfaceCells;
|
||||||
|
surfaceCells = NULL;
|
||||||
delete [] startLocations;
|
delete [] startLocations;
|
||||||
|
startLocations = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Map::getSurfaceCellArraySize() const {
|
||||||
|
return (surfaceW * surfaceH);
|
||||||
|
}
|
||||||
|
|
||||||
|
SurfaceCell *Map::getSurfaceCell(int sx, int sy) const {
|
||||||
|
int arrayIndex = sy * surfaceW + sx;
|
||||||
|
if(arrayIndex >= getSurfaceCellArraySize()) {
|
||||||
|
throw runtime_error("arrayIndex >= getSurfaceCellArraySize()");
|
||||||
|
}
|
||||||
|
else if(surfaceCells == NULL) {
|
||||||
|
throw runtime_error("surfaceCells == NULL");
|
||||||
|
}
|
||||||
|
return &surfaceCells[arrayIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
int Map::getCellArraySize() const {
|
||||||
|
return (w * h);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cell *Map::getCell(int x, int y) const {
|
||||||
|
int arrayIndex = y * w + x;
|
||||||
|
if(arrayIndex >= getCellArraySize()) {
|
||||||
|
throw runtime_error("arrayIndex >= getCellArraySize()");
|
||||||
|
}
|
||||||
|
else if(cells == NULL) {
|
||||||
|
throw runtime_error("cells == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
return &cells[arrayIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2i Map::getStartLocation(int locationIndex) const {
|
||||||
|
if(locationIndex >= maxPlayers) {
|
||||||
|
throw runtime_error("locationIndex >= maxPlayers");
|
||||||
|
}
|
||||||
|
else if(startLocations == NULL) {
|
||||||
|
throw runtime_error("startLocations == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
return startLocations[locationIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::load(const string &path, TechTree *techTree, Tileset *tileset){
|
void Map::load(const string &path, TechTree *techTree, Tileset *tileset){
|
||||||
@@ -152,7 +197,7 @@ void Map::load(const string &path, TechTree *techTree, Tileset *tileset){
|
|||||||
|
|
||||||
//start locations
|
//start locations
|
||||||
startLocations= new Vec2i[maxPlayers];
|
startLocations= new Vec2i[maxPlayers];
|
||||||
for(int i=0; i<maxPlayers; ++i){
|
for(int i=0; i<maxPlayers; ++i) {
|
||||||
int x, y;
|
int x, y;
|
||||||
readBytes = fread(&x, sizeof(int32), 1, f);
|
readBytes = fread(&x, sizeof(int32), 1, f);
|
||||||
readBytes = fread(&y, sizeof(int32), 1, f);
|
readBytes = fread(&y, sizeof(int32), 1, f);
|
||||||
@@ -161,8 +206,8 @@ void Map::load(const string &path, TechTree *techTree, Tileset *tileset){
|
|||||||
|
|
||||||
|
|
||||||
//cells
|
//cells
|
||||||
cells= new Cell[w*h];
|
cells= new Cell[getCellArraySize()];
|
||||||
surfaceCells= new SurfaceCell[surfaceW*surfaceH];
|
surfaceCells= new SurfaceCell[getSurfaceCellArraySize()];
|
||||||
|
|
||||||
//read heightmap
|
//read heightmap
|
||||||
for(int j=0; j<surfaceH; ++j){
|
for(int j=0; j<surfaceH; ++j){
|
||||||
@@ -847,9 +892,9 @@ void Map::computeInterpolatedHeights(){
|
|||||||
|
|
||||||
void Map::smoothSurface(){
|
void Map::smoothSurface(){
|
||||||
|
|
||||||
float *oldHeights= new float[surfaceW*surfaceH];
|
float *oldHeights= new float[getSurfaceCellArraySize()];
|
||||||
|
|
||||||
for(int i=0; i<surfaceW*surfaceH; ++i){
|
for(int i=0; i < getSurfaceCellArraySize(); ++i) {
|
||||||
oldHeights[i]= surfaceCells[i].getHeight();
|
oldHeights[i]= surfaceCells[i].getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -177,9 +177,11 @@ public:
|
|||||||
void load(const string &path, TechTree *techTree, Tileset *tileset);
|
void load(const string &path, TechTree *techTree, Tileset *tileset);
|
||||||
|
|
||||||
//get
|
//get
|
||||||
Cell *getCell(int x, int y) const {return &cells[y*w+x];}
|
Cell *getCell(int x, int y) const;
|
||||||
|
int getCellArraySize() const;
|
||||||
Cell *getCell(const Vec2i &pos) const {return getCell(pos.x, pos.y);}
|
Cell *getCell(const Vec2i &pos) const {return getCell(pos.x, pos.y);}
|
||||||
SurfaceCell *getSurfaceCell(int sx, int sy) const {return &surfaceCells[sy*surfaceW+sx];}
|
int getSurfaceCellArraySize() const;
|
||||||
|
SurfaceCell *getSurfaceCell(int sx, int sy) const;
|
||||||
SurfaceCell *getSurfaceCell(const Vec2i &sPos) const {return getSurfaceCell(sPos.x, sPos.y);}
|
SurfaceCell *getSurfaceCell(const Vec2i &sPos) const {return getSurfaceCell(sPos.x, sPos.y);}
|
||||||
int getW() const {return w;}
|
int getW() const {return w;}
|
||||||
int getH() const {return h;}
|
int getH() const {return h;}
|
||||||
@@ -188,7 +190,7 @@ public:
|
|||||||
int getMaxPlayers() const {return maxPlayers;}
|
int getMaxPlayers() const {return maxPlayers;}
|
||||||
float getHeightFactor() const {return heightFactor;}
|
float getHeightFactor() const {return heightFactor;}
|
||||||
float getWaterLevel() const {return waterLevel;}
|
float getWaterLevel() const {return waterLevel;}
|
||||||
Vec2i getStartLocation(int loactionIndex) const {return startLocations[loactionIndex];}
|
Vec2i getStartLocation(int locationIndex) const;
|
||||||
bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel;}
|
bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel;}
|
||||||
bool getSubmerged(const Cell *c) const {return c->getHeight()<waterLevel;}
|
bool getSubmerged(const Cell *c) const {return c->getHeight()<waterLevel;}
|
||||||
bool getDeepSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel-(1.5f/heightFactor);}
|
bool getDeepSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel-(1.5f/heightFactor);}
|
||||||
|
@@ -113,7 +113,7 @@ void Tileset::load(const string &dir, Checksum *checksum){
|
|||||||
|
|
||||||
checksum->addFile(path);
|
checksum->addFile(path);
|
||||||
|
|
||||||
try{
|
try {
|
||||||
Logger::getInstance().add("Tileset: "+formatString(name), true);
|
Logger::getInstance().add("Tileset: "+formatString(name), true);
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
@@ -242,13 +242,13 @@ void Tileset::load(const string &dir, Checksum *checksum){
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(rnd<sunnyProb){
|
if(rnd < sunnyProb) {
|
||||||
weather= wSunny;
|
weather= wSunny;
|
||||||
}
|
}
|
||||||
else if(rnd<rainyProb){
|
else if(rnd < rainyProb) {
|
||||||
weather= wRainy;
|
weather= wRainy;
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
weather= wSnowy;
|
weather= wSnowy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ void Tileset::load(const string &dir, Checksum *checksum){
|
|||||||
|
|
||||||
}
|
}
|
||||||
//Exception handling (conversions and so on);
|
//Exception handling (conversions and so on);
|
||||||
catch(const exception &e){
|
catch(const exception &e) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||||
throw runtime_error("Error: " + path + "\n" + e.what());
|
throw runtime_error("Error: " + path + "\n" + e.what());
|
||||||
}
|
}
|
||||||
@@ -271,18 +271,16 @@ const Pixmap2D *Tileset::getSurfPixmap(int type, int var) const{
|
|||||||
return &surfPixmaps[type][var % vars];
|
return &surfPixmaps[type][var % vars];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture){
|
void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture) {
|
||||||
|
|
||||||
//center textures
|
//center textures
|
||||||
if(leftUp==rightUp && leftUp==leftDown && leftUp==rightDown){
|
if(leftUp == rightUp && leftUp == leftDown && leftUp == rightDown) {
|
||||||
|
|
||||||
//texture variation according to probability
|
//texture variation according to probability
|
||||||
float r= random.randRange(0.f, 1.f);
|
float r= random.randRange(0.f, 1.f);
|
||||||
int var= 0;
|
int var= 0;
|
||||||
float max= 0.f;
|
float max= 0.f;
|
||||||
for(int i=0; i<surfProbs[leftUp].size(); ++i){
|
for(int i=0; i < surfProbs[leftUp].size(); ++i) {
|
||||||
max+= surfProbs[leftUp][i];
|
max+= surfProbs[leftUp][i];
|
||||||
if(r<=max){
|
if(r <= max) {
|
||||||
var= i;
|
var= i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -292,13 +290,11 @@ void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, V
|
|||||||
coord= si.getCoord();
|
coord= si.getCoord();
|
||||||
texture= si.getTexture();
|
texture= si.getTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
//spatted textures
|
//spatted textures
|
||||||
else{
|
else {
|
||||||
int var= random.randRange(0, transitionVars);
|
int var= random.randRange(0, transitionVars);
|
||||||
|
|
||||||
SurfaceInfo si(
|
SurfaceInfo si( getSurfPixmap(leftUp, var),
|
||||||
getSurfPixmap(leftUp, var),
|
|
||||||
getSurfPixmap(rightUp, var),
|
getSurfPixmap(rightUp, var),
|
||||||
getSurfPixmap(leftDown, var),
|
getSurfPixmap(leftDown, var),
|
||||||
getSurfPixmap(rightDown, var));
|
getSurfPixmap(rightDown, var));
|
||||||
@@ -306,7 +302,6 @@ void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, V
|
|||||||
coord= si.getCoord();
|
coord= si.getCoord();
|
||||||
texture= si.getTexture();
|
texture= si.getTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}}// end namespace
|
}}// end namespace
|
||||||
|
@@ -246,9 +246,21 @@ void World::loadScenario(const string &path, Checksum *checksum){
|
|||||||
void World::updateAllFactionUnits() {
|
void World::updateAllFactionUnits() {
|
||||||
scriptManager->onTimerTriggerEvent();
|
scriptManager->onTimerTriggerEvent();
|
||||||
//units
|
//units
|
||||||
for(int i=0; i<getFactionCount(); ++i) {
|
int factionCount = getFactionCount();
|
||||||
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
|
for(int i = 0; i < factionCount; ++i) {
|
||||||
unitUpdater.updateUnit(getFaction(i)->getUnit(j));
|
Faction *faction = getFaction(i);
|
||||||
|
if(faction == NULL) {
|
||||||
|
throw runtime_error("faction == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
int unitCount = faction->getUnitCount();
|
||||||
|
for(int j = 0; j < unitCount; ++j) {
|
||||||
|
Unit *unit = faction->getUnit(j);
|
||||||
|
if(unit == NULL) {
|
||||||
|
throw runtime_error("unit == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
unitUpdater.updateUnit(unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,17 +274,27 @@ void World::underTakeDeadFactionUnits() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionIdxToTick = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick);
|
int factionCount = getFactionCount();
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionIdxToTick = %d, factionCount = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick,factionCount);
|
||||||
|
|
||||||
//undertake the dead
|
//undertake the dead
|
||||||
for(int i=0; i<getFactionCount(); ++i){
|
for(int i = 0; i< factionCount; ++i) {
|
||||||
if(factionIdxToTick == -1 || factionIdxToTick == i) {
|
if(factionIdxToTick == -1 || factionIdxToTick == i) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionIdxToTick = %d, i = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick,i);
|
Faction *faction = getFaction(i);
|
||||||
|
if(faction == NULL) {
|
||||||
|
throw runtime_error("faction == NULL");
|
||||||
|
}
|
||||||
|
int unitCount = faction->getUnitCount();
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionIdxToTick = %d, i = %d, unitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,factionIdxToTick,i,unitCount);
|
||||||
|
|
||||||
int unitCount = getFaction(i)->getUnitCount();
|
for(int j= unitCount - 1; j >= 0; j--) {
|
||||||
for(int j= unitCount - 1; j >= 0; j--){
|
Unit *unit= faction->getUnit(j);
|
||||||
Unit *unit= getFaction(i)->getUnit(j);
|
|
||||||
if(unit->getToBeUndertaken()) {
|
if(unit == NULL) {
|
||||||
|
throw runtime_error("unit == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(unit->getToBeUndertaken() == true) {
|
||||||
unit->undertake();
|
unit->undertake();
|
||||||
delete unit;
|
delete unit;
|
||||||
//j--;
|
//j--;
|
||||||
@@ -284,11 +306,18 @@ void World::underTakeDeadFactionUnits() {
|
|||||||
|
|
||||||
void World::updateAllFactionConsumableCosts() {
|
void World::updateAllFactionConsumableCosts() {
|
||||||
//food costs
|
//food costs
|
||||||
for(int i=0; i<techTree->getResourceTypeCount(); ++i){
|
int resourceTypeCount = techTree->getResourceTypeCount();
|
||||||
const ResourceType *rt= techTree->getResourceType(i);
|
int factionCount = getFactionCount();
|
||||||
if(rt->getClass() == rcConsumable && frameCount % (rt->getInterval() * GameConstants::updateFps)==0){
|
for(int i = 0; i < resourceTypeCount; ++i) {
|
||||||
for(int i=0; i<getFactionCount(); ++i){
|
const ResourceType *rt = techTree->getResourceType(i);
|
||||||
getFaction(i)->applyCostsOnInterval(rt);
|
if(rt != NULL && rt->getClass() == rcConsumable && frameCount % (rt->getInterval() * GameConstants::updateFps) == 0) {
|
||||||
|
for(int j = 0; j < factionCount; ++j) {
|
||||||
|
Faction *faction = getFaction(j);
|
||||||
|
if(faction == NULL) {
|
||||||
|
throw runtime_error("faction == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
faction->applyCostsOnInterval(rt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -415,35 +444,51 @@ void World::tick() {
|
|||||||
|
|
||||||
//increase hp
|
//increase hp
|
||||||
//int i = factionIdxToTick;
|
//int i = factionIdxToTick;
|
||||||
for(int i=0; i<getFactionCount(); ++i) {
|
int factionCount = getFactionCount();
|
||||||
|
for(int i = 0; i < factionCount; ++i) {
|
||||||
if(factionIdxToTick == -1 || i == factionIdxToTick) {
|
if(factionIdxToTick == -1 || i == factionIdxToTick) {
|
||||||
for(int j=0; j<getFaction(i)->getUnitCount(); ++j) {
|
Faction *faction = getFaction(i);
|
||||||
getFaction(i)->getUnit(j)->tick();
|
if(faction == NULL) {
|
||||||
|
throw runtime_error("faction == NULL");
|
||||||
|
}
|
||||||
|
int unitCount = faction->getUnitCount();
|
||||||
|
|
||||||
|
for(int j = 0; j < unitCount; ++j) {
|
||||||
|
Unit *unit = faction->getUnit(j);
|
||||||
|
if(unit == NULL) {
|
||||||
|
throw runtime_error("unit == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
unit->tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//compute resources balance
|
//compute resources balance
|
||||||
//int k = factionIdxToTick;
|
//int k = factionIdxToTick;
|
||||||
for(int k=0; k<getFactionCount(); ++k) {
|
factionCount = getFactionCount();
|
||||||
|
for(int k = 0; k < factionCount; ++k) {
|
||||||
if(factionIdxToTick == -1 || k == factionIdxToTick) {
|
if(factionIdxToTick == -1 || k == factionIdxToTick) {
|
||||||
Faction *faction= getFaction(k);
|
Faction *faction= getFaction(k);
|
||||||
|
if(faction == NULL) {
|
||||||
|
throw runtime_error("faction == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
//for each resource
|
//for each resource
|
||||||
for(int i=0; i<techTree->getResourceTypeCount(); ++i) {
|
for(int i = 0; i < techTree->getResourceTypeCount(); ++i) {
|
||||||
const ResourceType *rt= techTree->getResourceType(i);
|
const ResourceType *rt= techTree->getResourceType(i);
|
||||||
|
|
||||||
//if consumable
|
//if consumable
|
||||||
if(rt->getClass()==rcConsumable) {
|
if(rt != NULL && rt->getClass()==rcConsumable) {
|
||||||
int balance= 0;
|
int balance= 0;
|
||||||
for(int j=0; j<faction->getUnitCount(); ++j) {
|
for(int j = 0; j < faction->getUnitCount(); ++j) {
|
||||||
|
|
||||||
//if unit operative and has this cost
|
//if unit operative and has this cost
|
||||||
const Unit *u= faction->getUnit(j);
|
const Unit *u= faction->getUnit(j);
|
||||||
if(u->isOperative()) {
|
if(u != NULL && u->isOperative()) {
|
||||||
const Resource *r= u->getType()->getCost(rt);
|
const Resource *r= u->getType()->getCost(rt);
|
||||||
if(r!=NULL) {
|
if(r != NULL) {
|
||||||
balance-= u->getType()->getCost(rt)->getAmount();
|
balance -= u->getType()->getCost(rt)->getAmount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -459,7 +504,7 @@ void World::tick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Unit* World::findUnitById(int id) const {
|
Unit* World::findUnitById(int id) const {
|
||||||
for(int i= 0; i<getFactionCount(); ++i){
|
for(int i= 0; i<getFactionCount(); ++i) {
|
||||||
const Faction* faction= getFaction(i);
|
const Faction* faction= getFaction(i);
|
||||||
Unit* unit = faction->findUnit(id);
|
Unit* unit = faction->findUnit(id);
|
||||||
if(unit != NULL) {
|
if(unit != NULL) {
|
||||||
@@ -469,36 +514,42 @@ Unit* World::findUnitById(int id) const {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UnitType* World::findUnitTypeById(const FactionType* factionType, int id){
|
const UnitType* World::findUnitTypeById(const FactionType* factionType, int id) {
|
||||||
for(int i= 0; i<factionType->getUnitTypeCount(); ++i){
|
if(factionType == NULL) {
|
||||||
const UnitType* unitType= factionType->getUnitType(i);
|
throw runtime_error("factionType == NULL");
|
||||||
|
}
|
||||||
if(unitType->getId()==id){
|
for(int i= 0; i < factionType->getUnitTypeCount(); ++i) {
|
||||||
|
const UnitType *unitType = factionType->getUnitType(i);
|
||||||
|
if(unitType != NULL && unitType->getId() == id) {
|
||||||
return unitType;
|
return unitType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//looks for a place for a unit around a start lociacion, returns true if succeded
|
//looks for a place for a unit around a start location, returns true if succeded
|
||||||
bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated){
|
bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated) {
|
||||||
|
if(unit == NULL) {
|
||||||
|
throw runtime_error("unit == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
bool freeSpace=false;
|
bool freeSpace=false;
|
||||||
int size= unit->getType()->getSize();
|
int size= unit->getType()->getSize();
|
||||||
Field currField= unit->getCurrField();
|
Field currField= unit->getCurrField();
|
||||||
|
|
||||||
for(int r=1; r<radius; r++){
|
for(int r = 1; r < radius; r++) {
|
||||||
for(int i=-r; i<r; ++i){
|
for(int i = -r; i < r; ++i) {
|
||||||
for(int j=-r; j<r; ++j){
|
for(int j = -r; j < r; ++j) {
|
||||||
Vec2i pos= Vec2i(i,j)+startLoc;
|
Vec2i pos= Vec2i(i,j) + startLoc;
|
||||||
if(spaciated){
|
if(spaciated) {
|
||||||
const int spacing= 2;
|
const int spacing = 2;
|
||||||
freeSpace= map.isFreeCells(pos-Vec2i(spacing), size+spacing*2, currField);
|
freeSpace= map.isFreeCells(pos-Vec2i(spacing), size+spacing*2, currField);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
freeSpace= map.isFreeCells(pos, size, currField);
|
freeSpace= map.isFreeCells(pos, size, currField);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(freeSpace){
|
if(freeSpace) {
|
||||||
unit->setPos(pos);
|
unit->setPos(pos);
|
||||||
unit->setMeetingPos(pos-Vec2i(1));
|
unit->setMeetingPos(pos-Vec2i(1));
|
||||||
return true;
|
return true;
|
||||||
@@ -510,12 +561,16 @@ bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spacia
|
|||||||
}
|
}
|
||||||
|
|
||||||
//clears a unit old position from map and places new position
|
//clears a unit old position from map and places new position
|
||||||
void World::moveUnitCells(Unit *unit){
|
void World::moveUnitCells(Unit *unit) {
|
||||||
|
if(unit == NULL) {
|
||||||
|
throw runtime_error("unit == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
Vec2i newPos= unit->getTargetPos();
|
Vec2i newPos= unit->getTargetPos();
|
||||||
|
|
||||||
//newPos must be free or the same pos as current
|
//newPos must be free or the same pos as current
|
||||||
assert(map.getCell(unit->getPos())->getUnit(unit->getCurrField())==unit || map.isFreeCell(newPos, unit->getCurrField()));
|
assert(map.getCell(unit->getPos())->getUnit(unit->getCurrField())==unit || map.isFreeCell(newPos, unit->getCurrField()));
|
||||||
// Only change cell plaement in map if the new position is different
|
// Only change cell placement in map if the new position is different
|
||||||
// from the old one
|
// from the old one
|
||||||
if(newPos != unit->getPos()) {
|
if(newPos != unit->getPos()) {
|
||||||
map.clearUnitCells(unit, unit->getPos());
|
map.clearUnitCells(unit, unit->getPos());
|
||||||
@@ -525,10 +580,10 @@ void World::moveUnitCells(Unit *unit){
|
|||||||
unit->getFaction()->addCloseResourceTargetToCache(newPos);
|
unit->getFaction()->addCloseResourceTargetToCache(newPos);
|
||||||
|
|
||||||
//water splash
|
//water splash
|
||||||
if(tileset.getWaterEffects() && unit->getCurrField()==fLand){
|
if(tileset.getWaterEffects() && unit->getCurrField() == fLand) {
|
||||||
if(map.getSubmerged(map.getCell(unit->getLastPos()))){
|
if(map.getSubmerged(map.getCell(unit->getLastPos()))) {
|
||||||
int unitSize=unit->getType()->getSize();
|
int unitSize= unit->getType()->getSize();
|
||||||
for(int i=0; i<3; ++i){
|
for(int i = 0; i < 3; ++i) {
|
||||||
waterEffects.addWaterSplash(
|
waterEffects.addWaterSplash(
|
||||||
Vec2f(unit->getLastPos().x+(float)unitSize/2.0f+random.randRange(-0.9f, -0.1f), unit->getLastPos().y+random.randRange(-0.9f, -0.1f)+(float)unitSize/2.0f), unit->getType()->getSize());
|
Vec2f(unit->getLastPos().x+(float)unitSize/2.0f+random.randRange(-0.9f, -0.1f), unit->getLastPos().y+random.randRange(-0.9f, -0.1f)+(float)unitSize/2.0f), unit->getType()->getSize());
|
||||||
}
|
}
|
||||||
@@ -539,29 +594,40 @@ void World::moveUnitCells(Unit *unit){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//returns the nearest unit that can store a type of resource given a position and a faction
|
//returns the nearest unit that can store a type of resource given a position and a faction
|
||||||
Unit *World::nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt){
|
Unit *World::nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt) {
|
||||||
float currDist= infinity;
|
float currDist= infinity;
|
||||||
Unit *currUnit= NULL;
|
Unit *currUnit= NULL;
|
||||||
|
|
||||||
for(int i=0; i<getFaction(factionIndex)->getUnitCount(); ++i){
|
if(factionIndex >= getFactionCount()) {
|
||||||
|
throw runtime_error("factionIndex >= getFactionCount()");
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i < getFaction(factionIndex)->getUnitCount(); ++i) {
|
||||||
Unit *u= getFaction(factionIndex)->getUnit(i);
|
Unit *u= getFaction(factionIndex)->getUnit(i);
|
||||||
|
if(u != NULL) {
|
||||||
float tmpDist= u->getPos().dist(pos);
|
float tmpDist= u->getPos().dist(pos);
|
||||||
if(tmpDist<currDist && u->getType()->getStore(rt)>0 && u->isOperative()){
|
if(tmpDist < currDist && u->getType()->getStore(rt) > 0 && u->isOperative()) {
|
||||||
currDist= tmpDist;
|
currDist= tmpDist;
|
||||||
currUnit= u;
|
currUnit= u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return currUnit;
|
return currUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::toRenderUnit(const Unit *unit, const Quad2i &visibleQuad) const{
|
bool World::toRenderUnit(const Unit *unit, const Quad2i &visibleQuad) const {
|
||||||
|
if(unit == NULL) {
|
||||||
|
throw runtime_error("unit == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
//a unit is rendered if it is in a visible cell or is attacking a unit in a visible cell
|
//a unit is rendered if it is in a visible cell or is attacking a unit in a visible cell
|
||||||
return
|
return visibleQuad.isInside(unit->getPos()) && toRenderUnit(unit);
|
||||||
visibleQuad.isInside(unit->getPos()) &&
|
|
||||||
toRenderUnit(unit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::toRenderUnit(const Unit *unit) const{
|
bool World::toRenderUnit(const Unit *unit) const {
|
||||||
|
if(unit == NULL) {
|
||||||
|
throw runtime_error("unit == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
(map.getSurfaceCell(Map::toSurfCoords(unit->getCenteredPos()))->isVisible(thisTeamIndex) &&
|
(map.getSurfaceCell(Map::toSurfCoords(unit->getCenteredPos()))->isVisible(thisTeamIndex) &&
|
||||||
@@ -571,10 +637,10 @@ bool World::toRenderUnit(const Unit *unit) const{
|
|||||||
map.getSurfaceCell(Map::toSurfCoords(unit->getTargetPos()))->isExplored(thisTeamIndex));
|
map.getSurfaceCell(Map::toSurfCoords(unit->getTargetPos()))->isExplored(thisTeamIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::createUnit(const string &unitName, int factionIndex, const Vec2i &pos){
|
void World::createUnit(const string &unitName, int factionIndex, const Vec2i &pos) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitName [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitName [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex);
|
||||||
|
|
||||||
if(factionIndex<factions.size()){
|
if(factionIndex < factions.size()) {
|
||||||
Faction* faction= &factions[factionIndex];
|
Faction* faction= &factions[factionIndex];
|
||||||
|
|
||||||
if(faction->getIndex() != factionIndex) {
|
if(faction->getIndex() != factionIndex) {
|
||||||
@@ -600,49 +666,47 @@ void World::createUnit(const string &unitName, int factionIndex, const Vec2i &po
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit created for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit created for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str());
|
||||||
|
|
||||||
if(placeUnit(pos, generationArea, unit, true)){
|
if(placeUnit(pos, generationArea, unit, true)) {
|
||||||
unit->create(true);
|
unit->create(true);
|
||||||
unit->born();
|
unit->born();
|
||||||
scriptManager->onUnitCreated(unit);
|
scriptManager->onUnitCreated(unit);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("Unit cant be placed");
|
throw runtime_error("Unit cant be placed");
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit created for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit created for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw runtime_error("Invalid faction index in createUnitAtPosition: " + intToStr(factionIndex));
|
throw runtime_error("Invalid faction index in createUnitAtPosition: " + intToStr(factionIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::giveResource(const string &resourceName, int factionIndex, int amount){
|
void World::giveResource(const string &resourceName, int factionIndex, int amount) {
|
||||||
if(factionIndex<factions.size()){
|
if(factionIndex < factions.size()) {
|
||||||
Faction* faction= &factions[factionIndex];
|
Faction* faction= &factions[factionIndex];
|
||||||
const ResourceType* rt= techTree->getResourceType(resourceName);
|
const ResourceType* rt= techTree->getResourceType(resourceName);
|
||||||
faction->incResourceAmount(rt, amount);
|
faction->incResourceAmount(rt, amount);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw runtime_error("Invalid faction index in giveResource: " + intToStr(factionIndex));
|
throw runtime_error("Invalid faction index in giveResource: " + intToStr(factionIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::givePositionCommand(int unitId, const string &commandName, const Vec2i &pos){
|
void World::givePositionCommand(int unitId, const string &commandName, const Vec2i &pos) {
|
||||||
Unit* unit= findUnitById(unitId);
|
Unit* unit= findUnitById(unitId);
|
||||||
if(unit!=NULL){
|
if(unit != NULL) {
|
||||||
CommandClass cc;
|
CommandClass cc;
|
||||||
|
|
||||||
if(commandName=="move"){
|
if(commandName=="move") {
|
||||||
cc= ccMove;
|
cc= ccMove;
|
||||||
}
|
}
|
||||||
else if(commandName=="attack"){
|
else if(commandName=="attack") {
|
||||||
cc= ccAttack;
|
cc= ccAttack;
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("Invalid position commmand: " + commandName);
|
throw runtime_error("Invalid position commmand: " + commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,140 +714,158 @@ void World::givePositionCommand(int unitId, const string &commandName, const Vec
|
|||||||
unit->giveCommand(new Command( unit->getType()->getFirstCtOfClass(cc), pos ));
|
unit->giveCommand(new Command( unit->getType()->getFirstCtOfClass(cc), pos ));
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw runtime_error("Invalid unitId index in givePositionCommand: " + intToStr(unitId) + " commandName = " + commandName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void World::giveAttackCommand(int unitId, int unitToAttackId) {
|
void World::giveAttackCommand(int unitId, int unitToAttackId) {
|
||||||
Unit* unit= findUnitById(unitId);
|
Unit* unit= findUnitById(unitId);
|
||||||
if(unit != NULL){
|
if(unit != NULL) {
|
||||||
Unit* targetUnit = findUnitById(unitToAttackId);
|
Unit* targetUnit = findUnitById(unitToAttackId);
|
||||||
if(targetUnit != NULL) {
|
if(targetUnit != NULL) {
|
||||||
const CommandType *ct= unit->getType()->getFirstAttackCommand(targetUnit->getCurrField());
|
const CommandType *ct = unit->getType()->getFirstAttackCommand(targetUnit->getCurrField());
|
||||||
if(ct != NULL) {
|
if(ct != NULL) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit [%s] is attacking [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->getFullName().c_str(),targetUnit->getFullName().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit [%s] is attacking [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->getFullName().c_str(),targetUnit->getFullName().c_str());
|
||||||
unit->giveCommand(new Command(ct,targetUnit));
|
unit->giveCommand(new Command(ct,targetUnit));
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw runtime_error("Invalid ct in giveAttackCommand: " + intToStr(unitId) + " unitToAttackId = " + intToStr(unitToAttackId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw runtime_error("Invalid unitToAttackId index in giveAttackCommand: " + intToStr(unitId) + " unitToAttackId = " + intToStr(unitToAttackId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw runtime_error("Invalid unitId index in giveAttackCommand: " + intToStr(unitId) + " unitToAttackId = " + intToStr(unitToAttackId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::giveProductionCommand(int unitId, const string &producedName){
|
void World::giveProductionCommand(int unitId, const string &producedName) {
|
||||||
Unit *unit= findUnitById(unitId);
|
Unit *unit= findUnitById(unitId);
|
||||||
if(unit!=NULL){
|
if(unit != NULL) {
|
||||||
const UnitType *ut= unit->getType();
|
const UnitType *ut= unit->getType();
|
||||||
|
|
||||||
//Search for a command that can produce the unit
|
//Search for a command that can produce the unit
|
||||||
for(int i= 0; i<ut->getCommandTypeCount(); ++i){
|
for(int i= 0; i< ut->getCommandTypeCount(); ++i) {
|
||||||
const CommandType* ct= ut->getCommandType(i);
|
const CommandType* ct= ut->getCommandType(i);
|
||||||
if(ct->getClass()==ccProduce){
|
if(ct != NULL && ct->getClass() == ccProduce) {
|
||||||
const ProduceCommandType *pct= static_cast<const ProduceCommandType*>(ct);
|
const ProduceCommandType *pct= static_cast<const ProduceCommandType*>(ct);
|
||||||
if(pct->getProducedUnit()->getName()==producedName){
|
if(pct != NULL && pct->getProducedUnit()->getName() == producedName) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
unit->giveCommand(new Command(pct));
|
unit->giveCommand(new Command(pct));
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw runtime_error("Invalid unitId index in giveProductionCommand: " + intToStr(unitId) + " producedName = " + producedName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::giveUpgradeCommand(int unitId, const string &upgradeName){
|
void World::giveUpgradeCommand(int unitId, const string &upgradeName) {
|
||||||
Unit *unit= findUnitById(unitId);
|
Unit *unit= findUnitById(unitId);
|
||||||
if(unit!=NULL){
|
if(unit != NULL) {
|
||||||
const UnitType *ut= unit->getType();
|
const UnitType *ut= unit->getType();
|
||||||
|
|
||||||
//Search for a command that can produce the unit
|
//Search for a command that can produce the unit
|
||||||
for(int i= 0; i<ut->getCommandTypeCount(); ++i){
|
for(int i= 0; i < ut->getCommandTypeCount(); ++i) {
|
||||||
const CommandType* ct= ut->getCommandType(i);
|
const CommandType* ct= ut->getCommandType(i);
|
||||||
if(ct->getClass()==ccUpgrade){
|
if(ct != NULL && ct->getClass() == ccUpgrade) {
|
||||||
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(ct);
|
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(ct);
|
||||||
if(uct->getProducedUpgrade()->getName()==upgradeName){
|
if(uct != NULL && uct->getProducedUpgrade()->getName() == upgradeName) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
unit->giveCommand(new Command(uct));
|
unit->giveCommand(new Command(uct));
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw runtime_error("Invalid unitId index in giveUpgradeCommand: " + intToStr(unitId) + " upgradeName = " + upgradeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int World::getResourceAmount(const string &resourceName, int factionIndex){
|
int World::getResourceAmount(const string &resourceName, int factionIndex) {
|
||||||
if(factionIndex<factions.size()){
|
if(factionIndex < factions.size()) {
|
||||||
Faction* faction= &factions[factionIndex];
|
Faction* faction= &factions[factionIndex];
|
||||||
const ResourceType* rt= techTree->getResourceType(resourceName);
|
const ResourceType* rt= techTree->getResourceType(resourceName);
|
||||||
return faction->getResource(rt)->getAmount();
|
return faction->getResource(rt)->getAmount();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
throw runtime_error("Invalid faction index in giveResource: " + intToStr(factionIndex) + " resourceName = " + resourceName);
|
||||||
throw runtime_error("Invalid faction index in giveResource: " + intToStr(factionIndex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i World::getStartLocation(int factionIndex){
|
Vec2i World::getStartLocation(int factionIndex) {
|
||||||
if(factionIndex<factions.size()){
|
if(factionIndex < factions.size()) {
|
||||||
Faction* faction= &factions[factionIndex];
|
Faction* faction= &factions[factionIndex];
|
||||||
return map.getStartLocation(faction->getStartLocationIndex());
|
return map.getStartLocation(faction->getStartLocationIndex());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw runtime_error("Invalid faction index in getStartLocation: " + intToStr(factionIndex));
|
throw runtime_error("Invalid faction index in getStartLocation: " + intToStr(factionIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i World::getUnitPosition(int unitId){
|
Vec2i World::getUnitPosition(int unitId) {
|
||||||
Unit* unit= findUnitById(unitId);
|
Unit* unit= findUnitById(unitId);
|
||||||
if(unit==NULL){
|
if(unit == NULL) {
|
||||||
throw runtime_error("Can not find unit to get position");
|
throw runtime_error("Can not find unit to get position unitId = " + intToStr(unitId));
|
||||||
}
|
}
|
||||||
return unit->getPos();
|
return unit->getPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
int World::getUnitFactionIndex(int unitId){
|
int World::getUnitFactionIndex(int unitId) {
|
||||||
Unit* unit= findUnitById(unitId);
|
Unit* unit= findUnitById(unitId);
|
||||||
if(unit==NULL){
|
if(unit == NULL) {
|
||||||
throw runtime_error("Can not find unit to get position");
|
throw runtime_error("Can not find Faction unit to get position unitId = " + intToStr(unitId));
|
||||||
}
|
}
|
||||||
return unit->getFactionIndex();
|
return unit->getFactionIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
int World::getUnitCount(int factionIndex){
|
int World::getUnitCount(int factionIndex) {
|
||||||
if(factionIndex<factions.size()){
|
if(factionIndex < factions.size()) {
|
||||||
Faction* faction= &factions[factionIndex];
|
Faction* faction= &factions[factionIndex];
|
||||||
int count= 0;
|
int count= 0;
|
||||||
|
|
||||||
for(int i= 0; i<faction->getUnitCount(); ++i){
|
for(int i= 0; i < faction->getUnitCount(); ++i) {
|
||||||
const Unit* unit= faction->getUnit(i);
|
const Unit* unit= faction->getUnit(i);
|
||||||
if(unit->isAlive()){
|
if(unit != NULL && unit->isAlive()) {
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw runtime_error("Invalid faction index in getUnitCount: " + intToStr(factionIndex));
|
throw runtime_error("Invalid faction index in getUnitCount: " + intToStr(factionIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int World::getUnitCountOfType(int factionIndex, const string &typeName){
|
int World::getUnitCountOfType(int factionIndex, const string &typeName) {
|
||||||
if(factionIndex<factions.size()){
|
if(factionIndex < factions.size()) {
|
||||||
Faction* faction= &factions[factionIndex];
|
Faction* faction= &factions[factionIndex];
|
||||||
int count= 0;
|
int count= 0;
|
||||||
|
|
||||||
for(int i= 0; i< faction->getUnitCount(); ++i){
|
for(int i= 0; i< faction->getUnitCount(); ++i) {
|
||||||
const Unit* unit= faction->getUnit(i);
|
const Unit* unit= faction->getUnit(i);
|
||||||
if(unit->isAlive() && unit->getType()->getName()==typeName){
|
if(unit != NULL && unit->isAlive() && unit->getType()->getName() == typeName) {
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw runtime_error("Invalid faction index in getUnitCountOfType: " + intToStr(factionIndex));
|
throw runtime_error("Invalid faction index in getUnitCountOfType: " + intToStr(factionIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -793,7 +875,7 @@ int World::getUnitCountOfType(int factionIndex, const string &typeName){
|
|||||||
// ==================== private init ====================
|
// ==================== private init ====================
|
||||||
|
|
||||||
//init basic cell state
|
//init basic cell state
|
||||||
void World::initCells(bool fogOfWar){
|
void World::initCells(bool fogOfWar) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
Logger::getInstance().add("State cells", true);
|
Logger::getInstance().add("State cells", true);
|
||||||
@@ -801,6 +883,9 @@ void World::initCells(bool fogOfWar){
|
|||||||
for(int j=0; j< map.getSurfaceH(); ++j) {
|
for(int j=0; j< map.getSurfaceH(); ++j) {
|
||||||
|
|
||||||
SurfaceCell *sc= map.getSurfaceCell(i, j);
|
SurfaceCell *sc= map.getSurfaceCell(i, j);
|
||||||
|
if(sc == NULL) {
|
||||||
|
throw runtime_error("sc == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
sc->setFowTexCoord(Vec2f(
|
sc->setFowTexCoord(Vec2f(
|
||||||
i/(next2Power(map.getSurfaceW())-1.f),
|
i/(next2Power(map.getSurfaceW())-1.f),
|
||||||
@@ -820,18 +905,31 @@ void World::initCells(bool fogOfWar){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//init surface textures
|
//init surface textures
|
||||||
void World::initSplattedTextures(){
|
void World::initSplattedTextures() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
for(int i=0; i<map.getSurfaceW()-1; ++i){
|
for(int i = 0; i < map.getSurfaceW() - 1; ++i) {
|
||||||
for(int j=0; j<map.getSurfaceH()-1; ++j){
|
for(int j = 0; j < map.getSurfaceH() - 1; ++j) {
|
||||||
Vec2f coord;
|
Vec2f coord;
|
||||||
const Texture2D *texture=NULL;
|
const Texture2D *texture=NULL;
|
||||||
SurfaceCell *sc00= map.getSurfaceCell(i, j);
|
SurfaceCell *sc00= map.getSurfaceCell(i, j);
|
||||||
SurfaceCell *sc10= map.getSurfaceCell(i+1, j);
|
SurfaceCell *sc10= map.getSurfaceCell(i+1, j);
|
||||||
SurfaceCell *sc01= map.getSurfaceCell(i, j+1);
|
SurfaceCell *sc01= map.getSurfaceCell(i, j+1);
|
||||||
SurfaceCell *sc11= map.getSurfaceCell(i+1, j+1);
|
SurfaceCell *sc11= map.getSurfaceCell(i+1, j+1);
|
||||||
tileset.addSurfTex(
|
|
||||||
sc00->getSurfaceType(),
|
if(sc00 == NULL) {
|
||||||
|
throw runtime_error("sc00 == NULL");
|
||||||
|
}
|
||||||
|
if(sc10 == NULL) {
|
||||||
|
throw runtime_error("sc10 == NULL");
|
||||||
|
}
|
||||||
|
if(sc01 == NULL) {
|
||||||
|
throw runtime_error("sc01 == NULL");
|
||||||
|
}
|
||||||
|
if(sc11 == NULL) {
|
||||||
|
throw runtime_error("sc11 == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
tileset.addSurfTex( sc00->getSurfaceType(),
|
||||||
sc10->getSurfaceType(),
|
sc10->getSurfaceType(),
|
||||||
sc01->getSurfaceType(),
|
sc01->getSurfaceType(),
|
||||||
sc11->getSurfaceType(),
|
sc11->getSurfaceType(),
|
||||||
@@ -844,11 +942,15 @@ void World::initSplattedTextures(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//creates each faction looking at each faction name contained in GameSettings
|
//creates each faction looking at each faction name contained in GameSettings
|
||||||
void World::initFactionTypes(GameSettings *gs){
|
void World::initFactionTypes(GameSettings *gs) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
Logger::getInstance().add("Faction types", true);
|
Logger::getInstance().add("Faction types", true);
|
||||||
|
|
||||||
if(gs->getFactionCount() > map.getMaxPlayers()){
|
if(gs == NULL) {
|
||||||
|
throw runtime_error("gs == NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gs->getFactionCount() > map.getMaxPlayers()) {
|
||||||
throw runtime_error("This map only supports "+intToStr(map.getMaxPlayers())+" players");
|
throw runtime_error("This map only supports "+intToStr(map.getMaxPlayers())+" players");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,8 +967,10 @@ void World::initFactionTypes(GameSettings *gs){
|
|||||||
|
|
||||||
for(int i=0; i < factions.size(); ++i) {
|
for(int i=0; i < factions.size(); ++i) {
|
||||||
FactionType *ft= techTree->getTypeByName(gs->getFactionTypeName(i));
|
FactionType *ft= techTree->getTypeByName(gs->getFactionTypeName(i));
|
||||||
factions[i].init(
|
if(ft == NULL) {
|
||||||
ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i),
|
throw runtime_error("ft == NULL");
|
||||||
|
}
|
||||||
|
factions[i].init(ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i),
|
||||||
gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources());
|
gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources());
|
||||||
|
|
||||||
stats.setTeam(i, gs->getTeam(i));
|
stats.setTeam(i, gs->getTeam(i));
|
||||||
@@ -885,26 +989,30 @@ void World::initFactionTypes(GameSettings *gs){
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::initMinimap(){
|
void World::initMinimap() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
minimap.init(map.getW(), map.getH(), this, game->getGameSettings()->getFogOfWar());
|
minimap.init(map.getW(), map.getH(), this, game->getGameSettings()->getFogOfWar());
|
||||||
Logger::getInstance().add("Compute minimap surface", true);
|
Logger::getInstance().add("Compute minimap surface", true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
//place units randomly aroud start location
|
//place units randomly aroud start location
|
||||||
void World::initUnits(){
|
void World::initUnits() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
Logger::getInstance().add("Generate elements", true);
|
Logger::getInstance().add("Generate elements", true);
|
||||||
|
|
||||||
//put starting units
|
//put starting units
|
||||||
for(int i=0; i<getFactionCount(); ++i){
|
for(int i = 0; i < getFactionCount(); ++i) {
|
||||||
Faction *f= &factions[i];
|
Faction *f= &factions[i];
|
||||||
const FactionType *ft= f->getType();
|
const FactionType *ft= f->getType();
|
||||||
for(int j=0; j<ft->getStartingUnitCount(); ++j){
|
|
||||||
|
for(int j = 0; j < ft->getStartingUnitCount(); ++j) {
|
||||||
const UnitType *ut= ft->getStartingUnit(j);
|
const UnitType *ut= ft->getStartingUnit(j);
|
||||||
int initNumber= ft->getStartingUnitAmount(j);
|
int initNumber= ft->getStartingUnitAmount(j);
|
||||||
for(int l=0; l<initNumber; l++){
|
|
||||||
|
for(int l = 0; l < initNumber; l++) {
|
||||||
|
|
||||||
UnitPathInterface *newpath = NULL;
|
UnitPathInterface *newpath = NULL;
|
||||||
switch(game->getGameSettings()->getPathFinderType()) {
|
switch(game->getGameSettings()->getPathFinderType()) {
|
||||||
@@ -922,11 +1030,11 @@ void World::initUnits(){
|
|||||||
|
|
||||||
int startLocationIndex= f->getStartLocationIndex();
|
int startLocationIndex= f->getStartLocationIndex();
|
||||||
|
|
||||||
if(placeUnit(map.getStartLocation(startLocationIndex), generationArea, unit, true)){
|
if(placeUnit(map.getStartLocation(startLocationIndex), generationArea, unit, true)) {
|
||||||
unit->create(true);
|
unit->create(true);
|
||||||
unit->born();
|
unit->born();
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("Unit cant be placed, this error is caused because there is no enough place to put the units near its start location, make a better map: "+unit->getType()->getName() + " Faction: "+intToStr(i));
|
throw runtime_error("Unit cant be placed, this error is caused because there is no enough place to put the units near its start location, make a better map: "+unit->getType()->getName() + " Faction: "+intToStr(i));
|
||||||
}
|
}
|
||||||
if (unit->getType()->hasSkillClass(scBeBuilt)) {
|
if (unit->getType()->hasSkillClass(scBeBuilt)) {
|
||||||
@@ -944,7 +1052,7 @@ void World::initUnits(){
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::initMap(){
|
void World::initMap() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
map.init();
|
map.init();
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -952,7 +1060,7 @@ void World::initMap(){
|
|||||||
|
|
||||||
// ==================== exploration ====================
|
// ==================== exploration ====================
|
||||||
|
|
||||||
void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){
|
void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex) {
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
|
@@ -25,10 +25,29 @@ namespace Shared{ namespace Graphics{ namespace Gl{
|
|||||||
class TextureGl {
|
class TextureGl {
|
||||||
protected:
|
protected:
|
||||||
GLuint handle;
|
GLuint handle;
|
||||||
|
GLuint renderBufferId;
|
||||||
|
GLuint frameBufferId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextureGl();
|
TextureGl();
|
||||||
|
virtual ~TextureGl();
|
||||||
|
|
||||||
GLuint getHandle() const {return handle;}
|
GLuint getHandle() const {return handle;}
|
||||||
|
GLuint getRenderBufferHandle() const {return renderBufferId;}
|
||||||
|
GLuint getFrameBufferHandle() const {return frameBufferId;}
|
||||||
|
|
||||||
|
void initRenderBuffer();
|
||||||
|
void initFrameBuffer();
|
||||||
|
void attachRenderBuffer();
|
||||||
|
void attachFrameBufferToTexture();
|
||||||
|
bool checkFrameBufferStatus();
|
||||||
|
void dettachFrameBufferFromTexture();
|
||||||
|
|
||||||
|
void setup_FBO_RBO();
|
||||||
|
void teardown_FBO_RBO();
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const = 0;
|
||||||
|
virtual int getTextureHeight() const = 0;
|
||||||
|
|
||||||
void OutputTextureDebugInfo(Texture::Format format, int components, const string path,uint64 rawSize,GLenum texType);
|
void OutputTextureDebugInfo(Texture::Format format, int components, const string path,uint64 rawSize,GLenum texType);
|
||||||
};
|
};
|
||||||
@@ -44,6 +63,9 @@ public:
|
|||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end(bool deletePixelBuffer=true);
|
virtual void end(bool deletePixelBuffer=true);
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const { return Texture1D::getTextureWidth();}
|
||||||
|
virtual int getTextureHeight() const { return Texture1D::getTextureHeight();}
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -57,6 +79,9 @@ public:
|
|||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end(bool deletePixelBuffer=true);
|
virtual void end(bool deletePixelBuffer=true);
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const { return Texture2D::getTextureWidth();}
|
||||||
|
virtual int getTextureHeight() const { return Texture2D::getTextureHeight();}
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -71,6 +96,9 @@ public:
|
|||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end(bool deletePixelBuffer=true);
|
virtual void end(bool deletePixelBuffer=true);
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const { return Texture3D::getTextureWidth();}
|
||||||
|
virtual int getTextureHeight() const { return Texture3D::getTextureHeight();}
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -85,6 +113,10 @@ public:
|
|||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end(bool deletePixelBuffer=true);
|
virtual void end(bool deletePixelBuffer=true);
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const { return TextureCube::getTextureWidth();}
|
||||||
|
virtual int getTextureHeight() const { return TextureCube::getTextureHeight();}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}}}//end namespace
|
}}}//end namespace
|
||||||
|
@@ -95,7 +95,7 @@ public:
|
|||||||
// class Texture1D
|
// class Texture1D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Texture1D: public Texture{
|
class Texture1D: public Texture {
|
||||||
protected:
|
protected:
|
||||||
Pixmap1D pixmap;
|
Pixmap1D pixmap;
|
||||||
|
|
||||||
@@ -107,6 +107,10 @@ public:
|
|||||||
virtual string getPath() const;
|
virtual string getPath() const;
|
||||||
virtual void deletePixels();
|
virtual void deletePixels();
|
||||||
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const {return pixmap.getW();}
|
||||||
|
virtual int getTextureHeight() const {return -1;}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -125,13 +129,16 @@ public:
|
|||||||
virtual string getPath() const;
|
virtual string getPath() const;
|
||||||
virtual void deletePixels();
|
virtual void deletePixels();
|
||||||
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const {return pixmap.getW();}
|
||||||
|
virtual int getTextureHeight() const {return pixmap.getH();}
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Texture3D
|
// class Texture3D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Texture3D: public Texture{
|
class Texture3D: public Texture {
|
||||||
protected:
|
protected:
|
||||||
Pixmap3D pixmap;
|
Pixmap3D pixmap;
|
||||||
|
|
||||||
@@ -143,6 +150,9 @@ public:
|
|||||||
virtual string getPath() const;
|
virtual string getPath() const;
|
||||||
virtual void deletePixels();
|
virtual void deletePixels();
|
||||||
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const {return pixmap.getW();}
|
||||||
|
virtual int getTextureHeight() const {return pixmap.getH();}
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -161,6 +171,9 @@ public:
|
|||||||
virtual string getPath() const;
|
virtual string getPath() const;
|
||||||
virtual void deletePixels();
|
virtual void deletePixels();
|
||||||
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
||||||
|
|
||||||
|
virtual int getTextureWidth() const {return -1;}
|
||||||
|
virtual int getTextureHeight() const {return -1;}
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -421,7 +421,130 @@ GLint toInternalFormatGl(Texture::Format format, int components){
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextureGl::TextureGl() {
|
TextureGl::TextureGl() {
|
||||||
handle=0;
|
handle = 0;
|
||||||
|
renderBufferId = 0;
|
||||||
|
frameBufferId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureGl::setup_FBO_RBO() {
|
||||||
|
if(getTextureWidth() < 0 || getTextureHeight() < 0) {
|
||||||
|
throw runtime_error("getTextureWidth() < 0 || getTextureHeight() < 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("getTextureWidth() = %d, getTextureHeight() = %d\n",getTextureWidth(),getTextureHeight());
|
||||||
|
|
||||||
|
GLint width=0;
|
||||||
|
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&width);
|
||||||
|
GLint height=0;
|
||||||
|
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&height);
|
||||||
|
|
||||||
|
printf("width = %d, height = %d\n",width,height);
|
||||||
|
|
||||||
|
//RGBA8 2D texture, 24 bit depth texture, 256x256
|
||||||
|
//glGenTextures(1, &color_tex);
|
||||||
|
//glBindTexture(GL_TEXTURE_2D, color_tex);
|
||||||
|
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
//NULL means reserve texture memory, but texels are undefined
|
||||||
|
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
//-------------------------
|
||||||
|
glGenFramebuffersEXT(1, &frameBufferId);
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferId);
|
||||||
|
//Attach 2D texture to this FBO
|
||||||
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, handle, 0);
|
||||||
|
//-------------------------
|
||||||
|
glGenRenderbuffersEXT(1, &renderBufferId);
|
||||||
|
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBufferId);
|
||||||
|
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, getTextureWidth(), getTextureHeight());
|
||||||
|
//-------------------------
|
||||||
|
//Attach depth buffer to FBO
|
||||||
|
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderBufferId);
|
||||||
|
//-------------------------
|
||||||
|
//Does the GPU support current FBO configuration?
|
||||||
|
GLenum status;
|
||||||
|
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case GL_FRAMEBUFFER_COMPLETE_EXT:
|
||||||
|
printf("FBO attachment OK!\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("FBO attachment BAD!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//-------------------------
|
||||||
|
//and now you can render to GL_TEXTURE_2D
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferId);
|
||||||
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureGl::teardown_FBO_RBO() {
|
||||||
|
//----------------
|
||||||
|
//Bind 0, which means render to back buffer
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
|
//And in the end, cleanup
|
||||||
|
//Delete resources
|
||||||
|
//glDeleteTextures(1, &handle);
|
||||||
|
glDeleteRenderbuffersEXT(1, &frameBufferId);
|
||||||
|
//Bind 0, which means render to back buffer, as a result, fb is unbound
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
|
glDeleteFramebuffersEXT(1, &frameBufferId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureGl::initRenderBuffer() {
|
||||||
|
// create a renderbuffer object to store depth info
|
||||||
|
glGenRenderbuffersEXT(1, &renderBufferId);
|
||||||
|
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBufferId);
|
||||||
|
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,getTextureWidth(), getTextureHeight());
|
||||||
|
//glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureGl::initFrameBuffer() {
|
||||||
|
// create a framebuffer object
|
||||||
|
glGenFramebuffersEXT(1, &frameBufferId);
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureGl::attachRenderBuffer() {
|
||||||
|
// attach the renderbuffer to depth attachment point
|
||||||
|
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, renderBufferId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureGl::attachFrameBufferToTexture() {
|
||||||
|
// attach the texture to FBO color attachment point
|
||||||
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, handle, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextureGl::checkFrameBufferStatus() {
|
||||||
|
// check FBO status
|
||||||
|
// Does the GPU support current FBO configuration?
|
||||||
|
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
|
||||||
|
if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
|
||||||
|
printf("checkFrameBufferStatus() status = %d [%X]\n",status,status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureGl::dettachFrameBufferFromTexture() {
|
||||||
|
// switch back to window-system-provided framebuffer
|
||||||
|
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureGl::~TextureGl() {
|
||||||
|
if(renderBufferId != 0) {
|
||||||
|
glDeleteRenderbuffersEXT(1, &renderBufferId);
|
||||||
|
renderBufferId = 0;
|
||||||
|
}
|
||||||
|
if(frameBufferId != 0) {
|
||||||
|
glDeleteFramebuffersEXT(1, &frameBufferId);
|
||||||
|
frameBufferId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -492,7 +615,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy) {
|
|||||||
if(error!=GL_NO_ERROR){
|
if(error!=GL_NO_ERROR){
|
||||||
//throw runtime_error("Error creating texture 1D");
|
//throw runtime_error("Error creating texture 1D");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error creating texture 1D, returned: %d [%s] w = %d, glCompressionFormat = %d",error,pixmap.getPath().c_str(),pixmap.getW(),glCompressionFormat);
|
sprintf(szBuf,"Error creating texture 1D, returned: %d (%X) [%s] w = %d, glCompressionFormat = %d",error,error,pixmap.getPath().c_str(),pixmap.getW(),glCompressionFormat);
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -579,17 +702,15 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) {
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexImage2D(
|
glTexImage2D(GL_TEXTURE_2D, 0, glCompressionFormat,pixmap.getW(),
|
||||||
GL_TEXTURE_2D, 0, glCompressionFormat,
|
pixmap.getH(),0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
pixmap.getW(), pixmap.getH(),
|
|
||||||
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
|
||||||
GLint error= glGetError();
|
|
||||||
|
|
||||||
|
GLint error= glGetError();
|
||||||
//throw runtime_error("TEST!");
|
//throw runtime_error("TEST!");
|
||||||
|
|
||||||
if(error != GL_NO_ERROR) {
|
if(error != GL_NO_ERROR) {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error creating texture 2D, returned: %d [%s] w = %d, h = %d, glInternalFormat = %d, glFormat = %d, glCompressionFormat = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),glInternalFormat,glFormat,glCompressionFormat);
|
sprintf(szBuf,"Error creating texture 2D, returned: %d (%X) [%s] w = %d, h = %d, glInternalFormat = %d, glFormat = %d, glCompressionFormat = %d",error,error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),glInternalFormat,glFormat,glCompressionFormat);
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -665,7 +786,7 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy) {
|
|||||||
if(error != GL_NO_ERROR) {
|
if(error != GL_NO_ERROR) {
|
||||||
//throw runtime_error("Error creating texture 3D");
|
//throw runtime_error("Error creating texture 3D");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error creating texture 3D, returned: %d [%s] w = %d, h = %d, d = %d, glCompressionFormat = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),pixmap.getD(),glCompressionFormat);
|
sprintf(szBuf,"Error creating texture 3D, returned: %d (%X) [%s] w = %d, h = %d, d = %d, glCompressionFormat = %d",error,error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),pixmap.getD(),glCompressionFormat);
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
@@ -762,7 +883,7 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy) {
|
|||||||
if(error != GL_NO_ERROR) {
|
if(error != GL_NO_ERROR) {
|
||||||
//throw runtime_error("Error creating texture cube");
|
//throw runtime_error("Error creating texture cube");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error creating texture cube, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH(),glCompressionFormat);
|
sprintf(szBuf,"Error creating texture cube, returned: %d (%X) [%s] w = %d, h = %d, glCompressionFormat = %d",error,error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH(),glCompressionFormat);
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -798,7 +919,7 @@ void TextureGl::OutputTextureDebugInfo(Texture::Format format, int components,co
|
|||||||
glGetTexLevelParameteriv(texType, 0, GL_TEXTURE_COMPRESSED, &compressed);
|
glGetTexLevelParameteriv(texType, 0, GL_TEXTURE_COMPRESSED, &compressed);
|
||||||
int error = glGetError();
|
int error = glGetError();
|
||||||
|
|
||||||
printf("**** Texture compressed status: %d, error [%d]\n",compressed,error);
|
printf("**** Texture compressed status: %d, error [%d] (%X)\n",compressed,error,error);
|
||||||
|
|
||||||
bool isCompressed = (compressed == 1);
|
bool isCompressed = (compressed == 1);
|
||||||
compressed=0;
|
compressed=0;
|
||||||
@@ -810,12 +931,12 @@ void TextureGl::OutputTextureDebugInfo(Texture::Format format, int components,co
|
|||||||
percent = ((double)compressed / (double)rawSize) * (double)100.0;
|
percent = ((double)compressed / (double)rawSize) * (double)100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("**** Texture image size in video RAM: %d [%.2f%%], error [%d]\n",compressed,percent,error);
|
printf("**** Texture image size in video RAM: %d [%.2f%%], error [%d] (%X)\n",compressed,percent,error,error);
|
||||||
|
|
||||||
compressed=0;
|
compressed=0;
|
||||||
glGetTexLevelParameteriv(texType, 0, GL_TEXTURE_INTERNAL_FORMAT, &compressed);
|
glGetTexLevelParameteriv(texType, 0, GL_TEXTURE_INTERNAL_FORMAT, &compressed);
|
||||||
error = glGetError();
|
error = glGetError();
|
||||||
printf("**** Texture image compression format used: %d, error [%d]\n",compressed,error);
|
printf("**** Texture image compression format used: %d, error [%d] (%X)\n",compressed,error,error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user