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