mirror of
https://github.com/glest/glest-source.git
synced 2025-10-04 11:21:36 +02:00
improved box selection ( much better regarding performance now and updates selection without moving the mouse )
This commit is contained in:
@@ -55,6 +55,7 @@ Game::Game(Program *program, const GameSettings *gameSettings):
|
|||||||
GameConstants::cameraFps= 100;
|
GameConstants::cameraFps= 100;
|
||||||
captureAvgTestStatus = false;
|
captureAvgTestStatus = false;
|
||||||
lastRenderLog2d = 0;
|
lastRenderLog2d = 0;
|
||||||
|
totalRenderFps = 0;
|
||||||
|
|
||||||
quitTriggeredIndicator = false;
|
quitTriggeredIndicator = false;
|
||||||
originalDisplayMsgCallback = NULL;
|
originalDisplayMsgCallback = NULL;
|
||||||
@@ -792,6 +793,7 @@ void Game::render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderFps++;
|
renderFps++;
|
||||||
|
totalRenderFps++;
|
||||||
renderWorker();
|
renderWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,7 +68,7 @@ private:
|
|||||||
int mouse2d;
|
int mouse2d;
|
||||||
int mouseX, mouseY; //coords win32Api
|
int mouseX, mouseY; //coords win32Api
|
||||||
int updateFps, lastUpdateFps, avgUpdateFps;
|
int updateFps, lastUpdateFps, avgUpdateFps;
|
||||||
int renderFps, lastRenderFps, avgRenderFps;
|
int totalRenderFps, renderFps, lastRenderFps, avgRenderFps;
|
||||||
bool paused;
|
bool paused;
|
||||||
bool gameOver;
|
bool gameOver;
|
||||||
bool renderNetworkStatus;
|
bool renderNetworkStatus;
|
||||||
@@ -113,6 +113,7 @@ public:
|
|||||||
World *getWorld() {return &world;}
|
World *getWorld() {return &world;}
|
||||||
const World *getWorld() const {return &world;}
|
const World *getWorld() const {return &world;}
|
||||||
|
|
||||||
|
const int getTotalRenderFps() const {return totalRenderFps;}
|
||||||
//init
|
//init
|
||||||
virtual void load();
|
virtual void load();
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
@@ -106,6 +106,9 @@ Gui::Gui(){
|
|||||||
selectingPos= false;
|
selectingPos= false;
|
||||||
selectingMeetingPoint= false;
|
selectingMeetingPoint= false;
|
||||||
activePos= invalidPos;
|
activePos= invalidPos;
|
||||||
|
lastQuadCalcFrame=0;
|
||||||
|
selectionCalculationFrameSkip=10;
|
||||||
|
minQuadSize=20;
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||||
}
|
}
|
||||||
@@ -115,6 +118,7 @@ void Gui::init(Game *game){
|
|||||||
this->gameCamera= game->getGameCamera();
|
this->gameCamera= game->getGameCamera();
|
||||||
this->console= game->getConsole();
|
this->console= game->getConsole();
|
||||||
this->world= game->getWorld();
|
this->world= game->getWorld();
|
||||||
|
this->game=game;
|
||||||
selection.init(this, world->getThisFactionIndex());
|
selection.init(this, world->getThisFactionIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,11 +145,6 @@ void Gui::invalidatePosObjWorld(){
|
|||||||
validPosObjWorld= false;
|
validPosObjWorld= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gui::setComputeSelectionFlag(){
|
|
||||||
computeSelection= true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ==================== reset state ====================
|
// ==================== reset state ====================
|
||||||
|
|
||||||
void Gui::resetState(){
|
void Gui::resetState(){
|
||||||
@@ -161,7 +160,10 @@ void Gui::resetState(){
|
|||||||
// ==================== events ====================
|
// ==================== events ====================
|
||||||
|
|
||||||
void Gui::update(){
|
void Gui::update(){
|
||||||
setComputeSelectionFlag();
|
|
||||||
|
if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize){
|
||||||
|
computeSelected(false,false);
|
||||||
|
}
|
||||||
mouse3d.update();
|
mouse3d.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +240,7 @@ void Gui::mouseDownLeftGraphics(int x, int y){
|
|||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectionQuad()\n",__FILE__,__FUNCTION__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectionQuad()\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
selectionQuad.setPosDown(Vec2i(x, y));
|
selectionQuad.setPosDown(Vec2i(x, y));
|
||||||
computeSelected(false);
|
computeSelected(false,false);
|
||||||
}
|
}
|
||||||
computeDisplay();
|
computeDisplay();
|
||||||
|
|
||||||
@@ -266,6 +268,10 @@ void Gui::mouseUpLeftGraphics(int x, int y){
|
|||||||
if(!selectingPos && !selectingMeetingPoint){
|
if(!selectingPos && !selectingMeetingPoint){
|
||||||
if(selectionQuad.isEnabled()){
|
if(selectionQuad.isEnabled()){
|
||||||
selectionQuad.setPosUp(Vec2i(x, y));
|
selectionQuad.setPosUp(Vec2i(x, y));
|
||||||
|
if(selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize)
|
||||||
|
{
|
||||||
|
computeSelected(false,true);
|
||||||
|
}
|
||||||
if(selection.isComandable() && random.randRange(0, 1)==0){
|
if(selection.isComandable() && random.randRange(0, 1)==0){
|
||||||
SoundRenderer::getInstance().playFx(
|
SoundRenderer::getInstance().playFx(
|
||||||
selection.getFrontUnit()->getType()->getSelectionSound(),
|
selection.getFrontUnit()->getType()->getSelectionSound(),
|
||||||
@@ -284,10 +290,7 @@ void Gui::mouseMoveGraphics(int x, int y){
|
|||||||
//compute selection
|
//compute selection
|
||||||
if(selectionQuad.isEnabled()){
|
if(selectionQuad.isEnabled()){
|
||||||
selectionQuad.setPosUp(Vec2i(x, y));
|
selectionQuad.setPosUp(Vec2i(x, y));
|
||||||
if(computeSelection){
|
computeSelected(false,false);
|
||||||
computeSelection= false;
|
|
||||||
computeSelected(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//compute position for building
|
//compute position for building
|
||||||
@@ -303,7 +306,7 @@ void Gui::mouseMoveGraphics(int x, int y){
|
|||||||
void Gui::mouseDoubleClickLeftGraphics(int x, int y){
|
void Gui::mouseDoubleClickLeftGraphics(int x, int y){
|
||||||
if(!selectingPos && !selectingMeetingPoint){
|
if(!selectingPos && !selectingMeetingPoint){
|
||||||
selectionQuad.setPosDown(Vec2i(x, y));
|
selectionQuad.setPosDown(Vec2i(x, y));
|
||||||
computeSelected(true);
|
computeSelected(true,true);
|
||||||
computeDisplay();
|
computeDisplay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -862,42 +865,50 @@ bool Gui::isSharedCommandClass(CommandClass commandClass){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gui::computeSelected(bool doubleClick){
|
void Gui::computeSelected(bool doubleClick, bool force){
|
||||||
Selection::UnitContainer units;
|
Selection::UnitContainer units;
|
||||||
Renderer::getInstance().computeSelected(units, selectionQuad.getPosDown(),
|
|
||||||
selectionQuad.getPosUp());
|
|
||||||
selectingBuilding= false;
|
|
||||||
activeCommandType= NULL;
|
|
||||||
|
|
||||||
//select all units of the same type if double click
|
if( force || ( lastQuadCalcFrame+selectionCalculationFrameSkip < game->getTotalRenderFps() ) ){
|
||||||
if(doubleClick && units.size() == 1) {
|
lastQuadCalcFrame=game->getTotalRenderFps();
|
||||||
const Unit *refUnit= units.front();
|
if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())<minQuadSize){
|
||||||
int factionIndex= refUnit->getFactionIndex();
|
Renderer::getInstance().computeSelected(units, selectionQuad.getPosDown(), selectionQuad.getPosDown());
|
||||||
for(int i=0; i< world->getFaction(factionIndex)->getUnitCount(); ++i) {
|
}
|
||||||
Unit *unit= world->getFaction(factionIndex)->getUnit(i);
|
else{
|
||||||
if(unit->getPos().dist(refUnit->getPos()) < doubleClickSelectionRadius &&
|
Renderer::getInstance().computeSelected(units, selectionQuad.getPosDown(), selectionQuad.getPosUp());
|
||||||
unit->getType() == refUnit->getType())
|
}
|
||||||
{
|
selectingBuilding= false;
|
||||||
units.push_back(unit);
|
activeCommandType= NULL;
|
||||||
|
|
||||||
|
//select all units of the same type if double click
|
||||||
|
if(doubleClick && units.size()==1){
|
||||||
|
const Unit *refUnit= units.front();
|
||||||
|
int factionIndex= refUnit->getFactionIndex();
|
||||||
|
for(int i=0; i<world->getFaction(factionIndex)->getUnitCount(); ++i){
|
||||||
|
Unit *unit= world->getFaction(factionIndex)->getUnit(i);
|
||||||
|
if(unit->getPos().dist(refUnit->getPos())<doubleClickSelectionRadius &&
|
||||||
|
unit->getType()==refUnit->getType())
|
||||||
|
{
|
||||||
|
units.push_back(unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
bool shiftDown= isKeyDown(vkShift);
|
||||||
bool shiftDown= isKeyDown(vkShift);
|
bool controlDown= isKeyDown(vkControl);
|
||||||
bool controlDown= isKeyDown(vkControl);
|
|
||||||
|
if(!shiftDown && !controlDown){
|
||||||
if(!shiftDown && !controlDown){
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.clear()\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.clear()\n",__FILE__,__FUNCTION__,__LINE__);
|
selection.clear();
|
||||||
selection.clear();
|
}
|
||||||
}
|
|
||||||
|
if(!controlDown){
|
||||||
if(!controlDown){
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.select(units)\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.select(units)\n",__FILE__,__FUNCTION__,__LINE__);
|
selection.select(units);
|
||||||
selection.select(units);
|
}
|
||||||
}
|
else{
|
||||||
else{
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] selection.unSelect(units)\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] selection.unSelect(units)\n",__FILE__,__FUNCTION__,__LINE__);
|
selection.unSelect(units);
|
||||||
selection.unSelect(units);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -106,13 +106,13 @@ private:
|
|||||||
RandomGen random;
|
RandomGen random;
|
||||||
const Commander *commander;
|
const Commander *commander;
|
||||||
const World *world;
|
const World *world;
|
||||||
|
const Game *game;
|
||||||
GameCamera *gameCamera;
|
GameCamera *gameCamera;
|
||||||
Console *console;
|
Console *console;
|
||||||
|
|
||||||
//Positions
|
//Positions
|
||||||
Vec2i posObjWorld; //world coords
|
Vec2i posObjWorld; //world coords
|
||||||
bool validPosObjWorld;
|
bool validPosObjWorld;
|
||||||
bool computeSelection;
|
|
||||||
|
|
||||||
//display
|
//display
|
||||||
const UnitType *choosenBuildingType;
|
const UnitType *choosenBuildingType;
|
||||||
@@ -125,6 +125,9 @@ private:
|
|||||||
Mouse3d mouse3d;
|
Mouse3d mouse3d;
|
||||||
Selection selection;
|
Selection selection;
|
||||||
SelectionQuad selectionQuad;
|
SelectionQuad selectionQuad;
|
||||||
|
int lastQuadCalcFrame;
|
||||||
|
int selectionCalculationFrameSkip;
|
||||||
|
int minQuadSize;
|
||||||
|
|
||||||
//states
|
//states
|
||||||
bool selectingBuilding;
|
bool selectingBuilding;
|
||||||
@@ -157,7 +160,6 @@ public:
|
|||||||
|
|
||||||
//set
|
//set
|
||||||
void invalidatePosObjWorld();
|
void invalidatePosObjWorld();
|
||||||
void setComputeSelectionFlag();
|
|
||||||
|
|
||||||
//events
|
//events
|
||||||
void update();
|
void update();
|
||||||
@@ -198,7 +200,7 @@ private:
|
|||||||
void computeInfoString(int posDisplay);
|
void computeInfoString(int posDisplay);
|
||||||
void addOrdersResultToConsole(CommandClass cc, CommandResult rr);
|
void addOrdersResultToConsole(CommandClass cc, CommandResult rr);
|
||||||
bool isSharedCommandClass(CommandClass commandClass);
|
bool isSharedCommandClass(CommandClass commandClass);
|
||||||
void computeSelected(bool doubleCkick);
|
void computeSelected(bool doubleCkick,bool force);
|
||||||
bool computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit);
|
bool computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ World::World(){
|
|||||||
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__);
|
||||||
Config &config= Config::getInstance();
|
Config &config= Config::getInstance();
|
||||||
|
|
||||||
staggeredFactionUpdates = false;
|
staggeredFactionUpdates = true;
|
||||||
ExploredCellsLookupItemCache.clear();
|
ExploredCellsLookupItemCache.clear();
|
||||||
ExploredCellsLookupItemCacheTimer.clear();
|
ExploredCellsLookupItemCacheTimer.clear();
|
||||||
ExploredCellsLookupItemCacheTimerCount = 0;
|
ExploredCellsLookupItemCacheTimerCount = 0;
|
||||||
|
Reference in New Issue
Block a user