- added a special thread to calculate interpolation to try to improve performance
This commit is contained in:
parent
54bcbf4303
commit
3547276699
|
@ -105,6 +105,93 @@ void MeshCallbackTeamColor::execute(const Mesh *mesh){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================
|
||||||
|
// class InterpolateTaskThread
|
||||||
|
// ===========================================================
|
||||||
|
|
||||||
|
InterpolateTaskThread::InterpolateTaskThread(InterpolateTaskCallbackInterface *interpolateTaskInterface)
|
||||||
|
: BaseThread() {
|
||||||
|
this->interpolateTaskInterface = interpolateTaskInterface;
|
||||||
|
nullEntityList();
|
||||||
|
this->taskSignalled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InterpolateTaskThread::setQuitStatus(bool value) {
|
||||||
|
BaseThread::setQuitStatus(value);
|
||||||
|
if(value == true) {
|
||||||
|
semaphoreTaskSignaller.signal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void InterpolateTaskThread::setRunningStatus(bool value) {
|
||||||
|
BaseThread::setRunningStatus(value);
|
||||||
|
if(value == false) {
|
||||||
|
semaphoreTaskSignaller.signal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InterpolateTaskThread::setTaskSignalled(std::vector<RenderEntity> *vctEntity) {
|
||||||
|
mutexTaskSignaller.p();
|
||||||
|
this->vctEntity = vctEntity;
|
||||||
|
mutexTaskSignaller.v();
|
||||||
|
|
||||||
|
if(this->vctEntity != NULL) {
|
||||||
|
semaphoreTaskSignaller.signal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InterpolateTaskThread::getTaskSignalled() {
|
||||||
|
bool result = false;
|
||||||
|
mutexTaskSignaller.p();
|
||||||
|
result = (vctEntity != NULL && vctEntity->size() > 0);
|
||||||
|
mutexTaskSignaller.v();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InterpolateTaskThread::nullEntityList() {
|
||||||
|
mutexTaskSignaller.p();
|
||||||
|
this->vctEntity = NULL;
|
||||||
|
mutexTaskSignaller.v();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InterpolateTaskThread::execute() {
|
||||||
|
try {
|
||||||
|
setRunningStatus(true);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
for(;this->interpolateTaskInterface != NULL;) {
|
||||||
|
if(getQuitStatus() == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int semValue = semaphoreTaskSignaller.waitTillSignalled();
|
||||||
|
|
||||||
|
if(getQuitStatus() == true) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getTaskSignalled() == true) {
|
||||||
|
if(vctEntity != NULL) {
|
||||||
|
this->interpolateTaskInterface->interpolateTask(*vctEntity);
|
||||||
|
nullEntityList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
catch(const exception &ex) {
|
||||||
|
setRunningStatus(false);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ex.what() = [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||||
|
|
||||||
|
throw runtime_error(ex.what());
|
||||||
|
}
|
||||||
|
setRunningStatus(false);
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// class Renderer
|
// class Renderer
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
@ -171,9 +258,16 @@ Renderer::Renderer(){
|
||||||
}
|
}
|
||||||
|
|
||||||
allowRotateUnits = config.getBool("AllowRotateUnits","0");
|
allowRotateUnits = config.getBool("AllowRotateUnits","0");
|
||||||
|
|
||||||
|
interpolateThread = new InterpolateTaskThread(this);
|
||||||
|
interpolateThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer(){
|
Renderer::~Renderer(){
|
||||||
|
BaseThread::shutdownAndWait(interpolateThread);
|
||||||
|
delete interpolateThread;
|
||||||
|
interpolateThread = NULL;
|
||||||
|
|
||||||
delete modelRenderer;
|
delete modelRenderer;
|
||||||
delete textRenderer;
|
delete textRenderer;
|
||||||
delete particleRenderer;
|
delete particleRenderer;
|
||||||
|
@ -1240,10 +1334,7 @@ void Renderer::renderSurface(){
|
||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderObjects(){
|
void Renderer::renderObjects() {
|
||||||
Chrono chrono;
|
|
||||||
chrono.start();
|
|
||||||
|
|
||||||
const World *world= game->getWorld();
|
const World *world= game->getWorld();
|
||||||
const Map *map= world->getMap();
|
const Map *map= world->getMap();
|
||||||
|
|
||||||
|
@ -1251,9 +1342,6 @@ void Renderer::renderObjects(){
|
||||||
const Texture2D *fowTex= world->getMinimap()->getFowTexture();
|
const Texture2D *fowTex= world->getMinimap()->getFowTexture();
|
||||||
Vec3f baseFogColor= world->getTileset()->getFogColor()*computeLightColor(world->getTimeFlow()->getTime());
|
Vec3f baseFogColor= world->getTileset()->getFogColor()*computeLightColor(world->getTimeFlow()->getTime());
|
||||||
|
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
chrono.start();
|
|
||||||
|
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_FOG_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_FOG_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT);
|
||||||
|
|
||||||
if(shadows==sShadowMapping){
|
if(shadows==sShadowMapping){
|
||||||
|
@ -1265,111 +1353,188 @@ void Renderer::renderObjects(){
|
||||||
static_cast<ModelRendererGl*>(modelRenderer)->setDuplicateTexCoords(true);
|
static_cast<ModelRendererGl*>(modelRenderer)->setDuplicateTexCoords(true);
|
||||||
enableProjectiveTexturing();
|
enableProjectiveTexturing();
|
||||||
}
|
}
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
chrono.start();
|
|
||||||
|
|
||||||
glActiveTexture(baseTexUnit);
|
glActiveTexture(baseTexUnit);
|
||||||
|
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
glAlphaFunc(GL_GREATER, 0.5f);
|
glAlphaFunc(GL_GREATER, 0.5f);
|
||||||
|
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
//modelRenderer->begin(true, true, false);
|
||||||
chrono.start();
|
|
||||||
|
|
||||||
modelRenderer->begin(true, true, false);
|
|
||||||
int thisTeamIndex= world->getThisTeamIndex();
|
int thisTeamIndex= world->getThisTeamIndex();
|
||||||
|
|
||||||
int loopCount1 = 0;
|
std::vector<RenderEntity> vctEntity;
|
||||||
int loopCount2 = 0;
|
|
||||||
|
|
||||||
Chrono chrono2;
|
|
||||||
int64 sectionA = 0;
|
|
||||||
int64 sectionB = 0;
|
|
||||||
int64 sectionC = 0;
|
|
||||||
int64 sectionD = 0;
|
|
||||||
int64 sectionE = 0;
|
|
||||||
int64 sectionF = 0;
|
|
||||||
int64 sectionG = 0;
|
|
||||||
int64 sectionH = 0;
|
|
||||||
|
|
||||||
PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
|
PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
|
||||||
while(pqi.next()){
|
while(pqi.next()){
|
||||||
|
const Vec2i &pos= pqi.getPos();
|
||||||
chrono2.start();
|
bool isPosVisible = map->isInside(pos.x, pos.y);
|
||||||
|
|
||||||
const Vec2i pos= pqi.getPos();
|
|
||||||
bool isPosVisible = map->isInside(pos);
|
|
||||||
|
|
||||||
sectionG += chrono2.getMillis();
|
|
||||||
chrono2.start();
|
|
||||||
|
|
||||||
if(isPosVisible == true) {
|
if(isPosVisible == true) {
|
||||||
|
Vec2i mapPos = Map::toSurfCoords(pos);
|
||||||
SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(pos));
|
SurfaceCell *sc= map->getSurfaceCell(mapPos.x, mapPos.y);
|
||||||
Object *o= sc->getObject();
|
Object *o= sc->getObject();
|
||||||
bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL);
|
bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL);
|
||||||
|
|
||||||
sectionH += chrono2.getMillis();
|
|
||||||
chrono2.start();
|
|
||||||
|
|
||||||
if(isExplored == true) {
|
if(isExplored == true) {
|
||||||
chrono2.start();
|
|
||||||
|
|
||||||
const Model *objModel= sc->getObject()->getModel();
|
/*
|
||||||
Vec3f v= o->getPos();
|
const Model *objModel= o->getModel();
|
||||||
|
const Vec3f &v= o->getConstPos();
|
||||||
|
|
||||||
//ambient and diffuse color is taken from cell color
|
//ambient and diffuse color is taken from cell color
|
||||||
float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale);
|
//!!!float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale);
|
||||||
|
float fowFactor= fowTex->getPixmap()->getPixelf(mapPos.x,mapPos.y);
|
||||||
|
|
||||||
Vec4f color= Vec4f(Vec3f(fowFactor), 1.f);
|
Vec4f color= Vec4f(Vec3f(fowFactor), 1.f);
|
||||||
glColor4fv(color.ptr());
|
glColor4fv(color.ptr());
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (color*ambFactor).ptr());
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (color*ambFactor).ptr());
|
||||||
glFogfv(GL_FOG_COLOR, (baseFogColor*fowFactor).ptr());
|
glFogfv(GL_FOG_COLOR, (baseFogColor*fowFactor).ptr());
|
||||||
|
|
||||||
sectionA += chrono2.getMillis();
|
|
||||||
chrono2.start();
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(v.x, v.y, v.z);
|
glTranslatef(v.x, v.y, v.z);
|
||||||
glRotatef(o->getRotation(), 0.f, 1.f, 0.f);
|
glRotatef(o->getRotation(), 0.f, 1.f, 0.f);
|
||||||
|
|
||||||
sectionB += chrono2.getMillis();
|
|
||||||
chrono2.start();
|
|
||||||
|
|
||||||
objModel->updateInterpolationData(0.f, true);
|
objModel->updateInterpolationData(0.f, true);
|
||||||
|
|
||||||
sectionC += chrono2.getMillis();
|
|
||||||
chrono2.start();
|
|
||||||
|
|
||||||
modelRenderer->render(objModel);
|
modelRenderer->render(objModel);
|
||||||
|
|
||||||
sectionD += chrono2.getMillis();
|
triangleCount+= objModel->getTriangleCount();
|
||||||
chrono2.start();
|
pointCount+= objModel->getVertexCount();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
*/
|
||||||
|
|
||||||
|
//renderObject(RenderEntity(o,mapPos),baseFogColor);
|
||||||
|
vctEntity.push_back(RenderEntity(o,mapPos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modelRenderer->begin(true, true, false);
|
||||||
|
renderObjectList(vctEntity,baseFogColor);
|
||||||
|
modelRenderer->end();
|
||||||
|
|
||||||
|
//restore
|
||||||
|
static_cast<ModelRendererGl*>(modelRenderer)->setDuplicateTexCoords(true);
|
||||||
|
glPopAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::interpolateTask(std::vector<RenderEntity> &vctEntity) {
|
||||||
|
for(int idx=0; idx < vctEntity.size(); ++idx) {
|
||||||
|
prepareObjectForRender(vctEntity[idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::renderObjectList(std::vector<RenderEntity> &vctEntity,const Vec3f &baseFogColor) {
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] vctEntity.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,vctEntity.size());
|
||||||
|
|
||||||
|
// Run interpolation threaded if the thread is created
|
||||||
|
if(interpolateThread != NULL) {
|
||||||
|
interpolateThread->setTaskSignalled(&vctEntity);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
interpolateTask(vctEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] vctEntity.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,vctEntity.size());
|
||||||
|
|
||||||
|
std::map<int,bool> entityPendingLookup;
|
||||||
|
|
||||||
|
int renderedObjectCount = 0;
|
||||||
|
for(bool done = false; done == false;) {
|
||||||
|
done = true;
|
||||||
|
for(int idx=0; idx < vctEntity.size(); ++idx) {
|
||||||
|
// already done, don't waste time
|
||||||
|
if(entityPendingLookup[idx] == true) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
RenderEntity &entity = vctEntity[idx];
|
||||||
|
if(entity.getState() == resInterpolated) {
|
||||||
|
done = false;
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] idx = %d\n",__FILE__,__FUNCTION__,__LINE__,idx);
|
||||||
|
|
||||||
|
renderObject(entity,baseFogColor);
|
||||||
|
entityPendingLookup[idx] = true;
|
||||||
|
renderedObjectCount++;
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] idx = %d renderedObjectCount = %d\n",__FILE__,__FUNCTION__,__LINE__,idx,renderedObjectCount);
|
||||||
|
}
|
||||||
|
else if(entity.getState() == resNone) {
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(done == false) {
|
||||||
|
sleep(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] vctEntity.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,vctEntity.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::prepareObjectForRender(RenderEntity &entity) {
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
Object *o = entity.o;
|
||||||
|
if(o != NULL) {
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
const Model *objModel= o->getModel();
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
if(objModel != NULL) {
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
objModel->updateInterpolationData(0.f, true);
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
entity.setState(resInterpolated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::renderObject(RenderEntity &entity,const Vec3f &baseFogColor) {
|
||||||
|
Object *o = entity.o;
|
||||||
|
Vec2i &mapPos = entity.mapPos;
|
||||||
|
if(o != NULL) {
|
||||||
|
const Model *objModel= o->getModel();
|
||||||
|
if(objModel != NULL) {
|
||||||
|
//objModel->updateInterpolationData(0.f, true);
|
||||||
|
|
||||||
|
const Vec3f &v= o->getConstPos();
|
||||||
|
|
||||||
|
//ambient and diffuse color is taken from cell color
|
||||||
|
const World *world= game->getWorld();
|
||||||
|
const Texture2D *fowTex= world->getMinimap()->getFowTexture();
|
||||||
|
|
||||||
|
//!!!float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale);
|
||||||
|
float fowFactor= fowTex->getPixmap()->getPixelf(mapPos.x,mapPos.y);
|
||||||
|
|
||||||
|
Vec4f color= Vec4f(Vec3f(fowFactor), 1.f);
|
||||||
|
glColor4fv(color.ptr());
|
||||||
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (color * ambFactor).ptr());
|
||||||
|
glFogfv(GL_FOG_COLOR, (baseFogColor * fowFactor).ptr());
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(v.x, v.y, v.z);
|
||||||
|
glRotatef(o->getRotation(), 0.f, 1.f, 0.f);
|
||||||
|
|
||||||
|
//objModel->updateInterpolationData(0.f, true);
|
||||||
|
|
||||||
|
modelRenderer->render(objModel);
|
||||||
|
|
||||||
triangleCount+= objModel->getTriangleCount();
|
triangleCount+= objModel->getTriangleCount();
|
||||||
pointCount+= objModel->getVertexCount();
|
pointCount+= objModel->getVertexCount();
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
sectionF += chrono2.getMillis();
|
entity.setState(resRendered);
|
||||||
|
|
||||||
loopCount2++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loopCount1++;
|
|
||||||
}
|
|
||||||
|
|
||||||
modelRenderer->end();
|
|
||||||
|
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d loopCount1 = %d loopCount2 = %d took msecs: %d [%d,%d,%d,%d,%d,%d,%d,%d]\n",__FILE__,__FUNCTION__,__LINE__,loopCount1,loopCount2,chrono.getMillis(),sectionG,sectionH,sectionA,sectionB,sectionC,sectionD,sectionE,sectionF);
|
|
||||||
chrono.start();
|
|
||||||
|
|
||||||
//restore
|
|
||||||
static_cast<ModelRendererGl*>(modelRenderer)->setDuplicateTexCoords(true);
|
|
||||||
glPopAttrib();
|
|
||||||
|
|
||||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::renderWater(){
|
void Renderer::renderWater(){
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "graphics_factory_gl.h"
|
#include "graphics_factory_gl.h"
|
||||||
#include "font_manager.h"
|
#include "font_manager.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include <vector>
|
||||||
|
#include "base_thread.h"
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
@ -49,6 +51,8 @@ using Shared::Graphics::ParticleSystem;
|
||||||
using Shared::Graphics::Pixmap2D;
|
using Shared::Graphics::Pixmap2D;
|
||||||
using Shared::Graphics::Camera;
|
using Shared::Graphics::Camera;
|
||||||
|
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
//non shared classes
|
//non shared classes
|
||||||
class Config;
|
class Config;
|
||||||
class Game;
|
class Game;
|
||||||
|
@ -57,6 +61,7 @@ class Console;
|
||||||
class MenuBackground;
|
class MenuBackground;
|
||||||
class ChatManager;
|
class ChatManager;
|
||||||
class Texture;
|
class Texture;
|
||||||
|
class Object;
|
||||||
|
|
||||||
enum ResourceScope{
|
enum ResourceScope{
|
||||||
rsGlobal,
|
rsGlobal,
|
||||||
|
@ -72,7 +77,96 @@ enum ResourceScope{
|
||||||
/// OpenGL renderer, uses the shared library
|
/// OpenGL renderer, uses the shared library
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
class Renderer{
|
enum RenderEntityState {
|
||||||
|
resNone,
|
||||||
|
resInterpolated,
|
||||||
|
resRendered
|
||||||
|
};
|
||||||
|
|
||||||
|
class RenderEntity {
|
||||||
|
protected:
|
||||||
|
Mutex mutex;
|
||||||
|
RenderEntityState state;
|
||||||
|
|
||||||
|
void CopyAll(const RenderEntity &obj) {
|
||||||
|
// Mutex doesn't like being copied.. DON'T do it
|
||||||
|
// Mutex mutex;
|
||||||
|
this->state = obj.state;
|
||||||
|
this->o = obj.o;
|
||||||
|
this->mapPos = obj.mapPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RenderEntity() {
|
||||||
|
this->o = NULL;
|
||||||
|
setState(resNone);
|
||||||
|
}
|
||||||
|
RenderEntity(Object *o, Vec2i &mapPos) {
|
||||||
|
this->o = o;
|
||||||
|
this->mapPos = mapPos;
|
||||||
|
setState(resNone);
|
||||||
|
}
|
||||||
|
RenderEntity(const RenderEntity &obj) {
|
||||||
|
CopyAll(obj);
|
||||||
|
}
|
||||||
|
RenderEntity & operator=(const RenderEntity &obj) {
|
||||||
|
CopyAll(obj);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object *o;
|
||||||
|
Vec2i mapPos;
|
||||||
|
|
||||||
|
RenderEntityState getState() {
|
||||||
|
RenderEntityState result;
|
||||||
|
mutex.p();
|
||||||
|
result = this->state;
|
||||||
|
mutex.v();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
void setState(RenderEntityState value) {
|
||||||
|
mutex.p();
|
||||||
|
this->state = value;
|
||||||
|
mutex.v();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// This interface describes the methods a callback object must implement
|
||||||
|
//
|
||||||
|
class InterpolateTaskCallbackInterface {
|
||||||
|
public:
|
||||||
|
virtual void interpolateTask(std::vector<RenderEntity> &vctEntity) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class InterpolateTaskThread : public BaseThread
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
InterpolateTaskCallbackInterface *interpolateTaskInterface;
|
||||||
|
|
||||||
|
Semaphore semaphoreTaskSignaller;
|
||||||
|
Mutex mutexTaskSignaller;
|
||||||
|
bool taskSignalled;
|
||||||
|
std::vector<RenderEntity> *vctEntity;
|
||||||
|
|
||||||
|
virtual void setQuitStatus(bool value);
|
||||||
|
virtual void setRunningStatus(bool value);
|
||||||
|
void nullEntityList();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
InterpolateTaskThread(InterpolateTaskCallbackInterface *interpolateTaskInterface);
|
||||||
|
virtual void execute();
|
||||||
|
void setTaskSignalled(std::vector<RenderEntity> *vctEntity);
|
||||||
|
bool getTaskSignalled();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Renderer : public InterpolateTaskCallbackInterface {
|
||||||
public:
|
public:
|
||||||
//progress bar
|
//progress bar
|
||||||
static const int maxProgressBar;
|
static const int maxProgressBar;
|
||||||
|
@ -169,6 +263,7 @@ private:
|
||||||
float waterAnim;
|
float waterAnim;
|
||||||
|
|
||||||
bool allowRotateUnits;
|
bool allowRotateUnits;
|
||||||
|
InterpolateTaskThread *interpolateThread;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Renderer();
|
Renderer();
|
||||||
|
@ -242,6 +337,12 @@ public:
|
||||||
//complex rendering
|
//complex rendering
|
||||||
void renderSurface();
|
void renderSurface();
|
||||||
void renderObjects();
|
void renderObjects();
|
||||||
|
void renderObject(RenderEntity &entity,const Vec3f &baseFogColor);
|
||||||
|
void prepareObjectForRender(RenderEntity &entity);
|
||||||
|
void renderObjectList(std::vector<RenderEntity> &vctEntity,const Vec3f &baseFogColor);
|
||||||
|
|
||||||
|
virtual void interpolateTask(std::vector<RenderEntity> &vctEntity);
|
||||||
|
|
||||||
void renderWater();
|
void renderWater();
|
||||||
void renderUnits();
|
void renderUnits();
|
||||||
void renderSelectionEffects();
|
void renderSelectionEffects();
|
||||||
|
|
|
@ -205,7 +205,7 @@ void Program::loopWorker() {
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
getWindow()->makeCurrentGl();
|
//getWindow()->makeCurrentGl();
|
||||||
|
|
||||||
//render
|
//render
|
||||||
assert(programState != NULL);
|
assert(programState != NULL);
|
||||||
|
|
|
@ -49,7 +49,7 @@ Object::~Object(){
|
||||||
}
|
}
|
||||||
|
|
||||||
const Model *Object::getModel() const{
|
const Model *Object::getModel() const{
|
||||||
return objectType==NULL? resource->getType()->getModel(): objectType->getModel(variation);
|
return objectType==NULL ? (resource != NULL && resource->getType() != NULL ? resource->getType()->getModel() : NULL ) : objectType->getModel(variation);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Object::getWalkable() const{
|
bool Object::getWalkable() const{
|
||||||
|
|
60
source/glest_game/type_instances/object.h
Normal file
60
source/glest_game/type_instances/object.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
#ifndef _GLEST_GAME_OBJECT_H_
|
||||||
|
#define _GLEST_GAME_OBJECT_H_
|
||||||
|
|
||||||
|
#include "model.h"
|
||||||
|
#include "vec.h"
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
class ObjectType;
|
||||||
|
class ResourceType;
|
||||||
|
class Resource;
|
||||||
|
|
||||||
|
using Shared::Graphics::Model;
|
||||||
|
using Shared::Graphics::Vec2i;
|
||||||
|
using Shared::Graphics::Vec3f;
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Object
|
||||||
|
//
|
||||||
|
/// A map object: tree, stone...
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class Object{
|
||||||
|
private:
|
||||||
|
ObjectType *objectType;
|
||||||
|
Resource *resource;
|
||||||
|
Vec3f pos;
|
||||||
|
float rotation;
|
||||||
|
int variation;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Object(ObjectType *objectType, const Vec3f &pos);
|
||||||
|
~Object();
|
||||||
|
|
||||||
|
void setHeight(float height) {pos.y= height;}
|
||||||
|
|
||||||
|
const ObjectType *getType() const {return objectType;}
|
||||||
|
Resource *getResource() const {return resource;}
|
||||||
|
Vec3f getPos() const {return pos;}
|
||||||
|
const Vec3f & getConstPos() const {return pos;}
|
||||||
|
float getRotation() {return rotation;}
|
||||||
|
const Model *getModel() const;
|
||||||
|
bool getWalkable() const;
|
||||||
|
|
||||||
|
void setResource(const ResourceType *resourceType, const Vec2i &pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -31,19 +31,19 @@ protected:
|
||||||
bool quit;
|
bool quit;
|
||||||
bool running;
|
bool running;
|
||||||
|
|
||||||
void setRunningStatus(bool value);
|
virtual void setRunningStatus(bool value);
|
||||||
void setQuitStatus(bool value);
|
virtual void setQuitStatus(bool value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseThread();
|
BaseThread();
|
||||||
~BaseThread();
|
~BaseThread();
|
||||||
virtual void execute()=0;
|
virtual void execute()=0;
|
||||||
|
|
||||||
void signalQuit();
|
virtual void signalQuit();
|
||||||
bool getQuitStatus();
|
virtual bool getQuitStatus();
|
||||||
bool getRunningStatus();
|
virtual bool getRunningStatus();
|
||||||
static void shutdownAndWait(BaseThread *ppThread);
|
static void shutdownAndWait(BaseThread *ppThread);
|
||||||
void shutdownAndWait();
|
virtual void shutdownAndWait();
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
82
source/shared_lib/include/platform/sdl/thread.h
Normal file
82
source/shared_lib/include/platform/sdl/thread.h
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#ifndef _SHARED_PLATFORM_THREAD_H_
|
||||||
|
#define _SHARED_PLATFORM_THREAD_H_
|
||||||
|
|
||||||
|
#include <SDL_thread.h>
|
||||||
|
#include <SDL_mutex.h>
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Thread
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
namespace Shared{ namespace Platform{
|
||||||
|
|
||||||
|
class Thread{
|
||||||
|
public:
|
||||||
|
enum Priority {
|
||||||
|
pIdle = 0,
|
||||||
|
pLow = 1,
|
||||||
|
pNormal = 2,
|
||||||
|
pHigh = 3,
|
||||||
|
pRealTime = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
SDL_Thread* thread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~Thread() {}
|
||||||
|
|
||||||
|
void start();
|
||||||
|
virtual void execute()=0;
|
||||||
|
void setPriority(Thread::Priority threadPriority);
|
||||||
|
void suspend();
|
||||||
|
void resume();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static int beginExecution(void *param);
|
||||||
|
};
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Mutex
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class Mutex{
|
||||||
|
private:
|
||||||
|
SDL_mutex* mutex;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Mutex();
|
||||||
|
~Mutex();
|
||||||
|
void p();
|
||||||
|
void v();
|
||||||
|
};
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Semaphore
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class Semaphore {
|
||||||
|
private:
|
||||||
|
SDL_sem* semaphore;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Semaphore(Uint32 initialValue = 0);
|
||||||
|
~Semaphore();
|
||||||
|
void signal();
|
||||||
|
int waitTillSignalled();
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -67,7 +67,7 @@ void FileCRCPreCacheThread::execute() {
|
||||||
SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface,
|
SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface,
|
||||||
unsigned int executionCount,
|
unsigned int executionCount,
|
||||||
unsigned int millisecsBetweenExecutions,
|
unsigned int millisecsBetweenExecutions,
|
||||||
bool needTaskSignal) {
|
bool needTaskSignal) : BaseThread() {
|
||||||
this->simpleTaskInterface = simpleTaskInterface;
|
this->simpleTaskInterface = simpleTaskInterface;
|
||||||
this->executionCount = executionCount;
|
this->executionCount = executionCount;
|
||||||
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
|
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
|
||||||
|
@ -79,7 +79,7 @@ void SimpleTaskThread::execute() {
|
||||||
try {
|
try {
|
||||||
setRunningStatus(true);
|
setRunningStatus(true);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
unsigned int idx = 0;
|
unsigned int idx = 0;
|
||||||
for(;this->simpleTaskInterface != NULL;) {
|
for(;this->simpleTaskInterface != NULL;) {
|
||||||
|
@ -93,7 +93,7 @@ void SimpleTaskThread::execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getQuitStatus() == true) {
|
if(getQuitStatus() == true) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,19 +108,19 @@ void SimpleTaskThread::execute() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(getQuitStatus() == true) {
|
if(getQuitStatus() == true) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(this->millisecsBetweenExecutions);
|
sleep(this->millisecsBetweenExecutions);
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
setRunningStatus(false);
|
setRunningStatus(false);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
throw runtime_error(ex.what());
|
throw runtime_error(ex.what());
|
||||||
}
|
}
|
||||||
|
@ -128,24 +128,24 @@ void SimpleTaskThread::execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleTaskThread::setTaskSignalled(bool value) {
|
void SimpleTaskThread::setTaskSignalled(bool value) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
mutexTaskSignaller.p();
|
mutexTaskSignaller.p();
|
||||||
taskSignalled = value;
|
taskSignalled = value;
|
||||||
mutexTaskSignaller.v();
|
mutexTaskSignaller.v();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimpleTaskThread::getTaskSignalled() {
|
bool SimpleTaskThread::getTaskSignalled() {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
mutexTaskSignaller.p();
|
mutexTaskSignaller.p();
|
||||||
retval = taskSignalled;
|
retval = taskSignalled;
|
||||||
mutexTaskSignaller.v();
|
mutexTaskSignaller.v();
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
89
source/shared_lib/sources/platform/sdl/thread.cpp
Normal file
89
source/shared_lib/sources/platform/sdl/thread.cpp
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
//This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||||
|
|
||||||
|
//You can redistribute this code and/or modify it under
|
||||||
|
//the terms of the GNU General Public License as published by the Free Software
|
||||||
|
//Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
//version.
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "noimpl.h"
|
||||||
|
|
||||||
|
namespace Shared{ namespace Platform{
|
||||||
|
|
||||||
|
// =====================================
|
||||||
|
// Threads
|
||||||
|
// =====================================
|
||||||
|
|
||||||
|
void Thread::start() {
|
||||||
|
thread = SDL_CreateThread(beginExecution, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::setPriority(Thread::Priority threadPriority) {
|
||||||
|
NOIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Thread::beginExecution(void* data) {
|
||||||
|
Thread* thread = static_cast<Thread*> (data);
|
||||||
|
thread->execute();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::suspend() {
|
||||||
|
NOIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::resume() {
|
||||||
|
NOIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================
|
||||||
|
// Mutex
|
||||||
|
// =====================================
|
||||||
|
|
||||||
|
Mutex::Mutex() {
|
||||||
|
mutex = SDL_CreateMutex();
|
||||||
|
if(mutex == 0)
|
||||||
|
throw std::runtime_error("Couldn't initialize mutex");
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex::~Mutex() {
|
||||||
|
SDL_DestroyMutex(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::p() {
|
||||||
|
SDL_mutexP(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::v() {
|
||||||
|
SDL_mutexV(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Semaphore
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
Semaphore::Semaphore(Uint32 initialValue) {
|
||||||
|
semaphore = SDL_CreateSemaphore(initialValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
Semaphore::~Semaphore() {
|
||||||
|
SDL_DestroySemaphore(semaphore);
|
||||||
|
semaphore = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Semaphore::signal() {
|
||||||
|
SDL_SemPost(semaphore);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Semaphore::waitTillSignalled() {
|
||||||
|
int semValue = SDL_SemWait(semaphore);
|
||||||
|
return semValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
88
source/shared_lib/sources/platform/win32/thread.cpp
Normal file
88
source/shared_lib/sources/platform/win32/thread.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
namespace Shared{ namespace Platform{
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Threads
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
ThreadId Thread::nextThreadId= threadIdBase;
|
||||||
|
|
||||||
|
void Thread::start(){
|
||||||
|
threadHandle= CreateThread(NULL, 0, beginExecution, this, 0, &nextThreadId);
|
||||||
|
nextThreadId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::setPriority(Thread::Priority threadPriority){
|
||||||
|
SetThreadPriority(threadHandle, threadPriority);
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD WINAPI Thread::beginExecution(void *param){
|
||||||
|
static_cast<Thread*>(param)->execute();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::suspend(){
|
||||||
|
SuspendThread(threadHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::resume(){
|
||||||
|
ResumeThread(threadHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Mutex
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
Mutex::Mutex(){
|
||||||
|
InitializeCriticalSection(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex::~Mutex(){
|
||||||
|
DeleteCriticalSection(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::p(){
|
||||||
|
EnterCriticalSection(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::v(){
|
||||||
|
LeaveCriticalSection(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Semaphore
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
Semaphore::Semaphore(Uint32 initialValue) {
|
||||||
|
semaphore = SDL_CreateSemaphore(initialValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
Semaphore::~Semaphore() {
|
||||||
|
SDL_DestroySemaphore(semaphore);
|
||||||
|
semaphore = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Semaphore::signal() {
|
||||||
|
SDL_SemPost(semaphore);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Semaphore::waitTillSignalled() {
|
||||||
|
int semValue = SDL_SemWait(semaphore);
|
||||||
|
return semValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
Loading…
Reference in New Issue
Block a user