command_queue.cpp

00001 /* $Id: command_queue.cpp 4998 2006-05-30 16:15:17Z Frostregen $ */
00002 
00003 #include "stdafx.h"
00004 #include "tile_type.h"
00005 #include "command_type.h"
00006 #include "command_func.h"
00007 #include "debug.h"
00008 #include "copy_paste.h"
00009 #include "command_queue.h"
00010 #include "settings_type.h"
00011 #include "gfx_func.h"
00012 #include "date_func.h"
00013 
00014 CopyPasteCommandQueue::~CopyPasteCommandQueue()
00015 {
00016   this->ClearCopyPasteCommandQueue();
00017 }
00018 
00022 void CopyPasteCommandQueue::CopyPasteQueueCommand(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd)
00023 {
00024   CommandContainer *cc = new CommandContainer;
00025   
00026   cc->tile = tile;
00027   cc->p1   = p1;
00028   cc->p2   = p2;
00029   cc->callback = callback;
00030   cc->cmd  = cmd;
00031   
00032   /* add it to the queue */
00033   this->queue.push(cc);
00034 }
00035 
00040 void CopyPasteCommandQueue::ExecuteNextCommand()
00041 {
00042   /* Check if queue is not empty */
00043   if (!this->queue.empty()) {
00044     /* backup and unset _shift_pressed */
00045     bool temp_shift_pressed = _shift_pressed;
00046     _shift_pressed = false;
00047     /* Get the command and execute it */
00048     DoCommandP(this->queue.front());
00049     /* restore _shift_pressed */
00050     _shift_pressed = temp_shift_pressed;
00051     /* delete this commandcontainer */
00052     {
00053       CommandContainer *cc = this->queue.front();
00054       this->queue.pop();
00055       delete cc;
00056     }
00057   }
00058 }
00059 
00062 void CopyPasteCommandQueue::ClearCopyPasteCommandQueue()
00063 {
00064   while (!this->queue.empty()) {
00065     this->queue.pop();
00066   }
00067 }
00068 
00069 void CallCopyPasteCommandQueueTick()
00070 {
00071   /* Process the command_queue */
00072   if (_settings_client.gui.cp_paste_speed < 255) {
00073     if ((_tick_counter % _settings_client.gui.cp_paste_speed) == 0) {
00074       _copy_paste_command_queue.ExecuteNextCommand();
00075     }
00076   }
00077 }