XGM Forum
Сайт - Статьи - Проекты - Ресурсы - Блоги

Форуме в режиме ТОЛЬКО ЧТЕНИЕ. Вы можете задать вопросы в Q/A на сайте, либо создать свой проект или ресурс.
Вернуться   XGM Forum > Warcraft> Академия: форум для вопросов> Jass
Ник
Пароль
Войти через VK в один клик
Сайт использует только имя.

Закрытая тема
 
Vampirrr
O_o
offline
Опыт: 19,286
Активность:
Нужна помощь с оптимизацией
в общем вот код
Код:
function Conditions takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetTriggerUnit()) == Player(0) and
    ( ( GetUnitTypeId(GetTriggerUnit()) == 'hmtt' ) or 
    ( GetUnitTypeId(GetTriggerUnit()) == 'ocat' ) or
    ( GetUnitTypeId(GetTriggerUnit()) == 'ebal' ) or 
    ( GetUnitTypeId(GetTriggerUnit()) == 'umtw' ) ) ) ) then
    endif
    return true
endfunction

function Owner_Condition_Red takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == Player(0) )
endfunction

function Owner_Condition_Blue takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == Player(1) )
endfunction

function Actions takes nothing returns nothing
local integer i
local real x
local real y
set x = (GetUnitX(GetTriggerUnit())) 
set y = (GetUnitY(GetTriggerUnit()))
set i = 0
    loop
    set i = i+1
    exitwhen i > 8
    exitwhen ( RectContainsLoc(gg_rct_Board, Location(x, y+256*i)) != true )
      exitwhen ( not ( IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Red))) == true ) ) 
      if (IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Red))) == true ) then
      if (IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Blue))) == true ) then
      call CreateNUnitsAtLoc( 1, 'e001', GetTriggerPlayer(), Location(x, y+256*i), 270 ) 
      else
      call CreateNUnitsAtLoc( 1, 'h000', GetTriggerPlayer(), Location(x, y+256*i), 270 ) 
      exitwhen ( not ( IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Blue))) == true ) )
      call CreateNUnitsAtLoc( 1, 'e001', GetTriggerPlayer(), Location(x, y+256*i), 270 ) 
      endif
      endif
    endloop
endfunction


Если возможно, избавьте от утечек и оптимизируйте. Игра пошаговая, сотни действий в секунду не выполняются, дикие конвертации кода тоже не нужны. Нужно просто поерхностное шлифование и избавление от самых неприятных гадостей. Спасибо.

Отредактировано Vampirrr, 04.01.2009 в 20:35.
Старый 04.01.2009, 20:09
ScorpioT1000
Работаем
offline
Опыт: отключен
а почему координаты переводятся в целый тип?
Старый 04.01.2009, 20:21
Vampirrr
O_o
offline
Опыт: 19,286
Активность:
ScorpioT1000, выдает cannot convert real to integer..просто наверное перменные сделать нужно не integer а real =)
Старый 04.01.2009, 20:25
ScorpioT1000
Работаем
offline
Опыт: отключен
ну я и говорю что они и должны быть с точкой зачем приводить к единицам
Старый 04.01.2009, 20:34
Vampirrr
O_o
offline
Опыт: 19,286
Активность:
ScorpioT1000, как бы это и все? O_o мне говорили что тут 3 утечки..

Отредактировано Vampirrr, 04.01.2009 в 20:51.
Старый 04.01.2009, 20:35
Integro
старожило
offline
Опыт: 630
Активность:
Код:
function Conditions takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetTriggerUnit()) == Player(0) and
    ( ( GetUnitTypeId(GetTriggerUnit()) == 'hmtt' ) or 
    ( GetUnitTypeId(GetTriggerUnit()) == 'ocat' ) or
    ( GetUnitTypeId(GetTriggerUnit()) == 'ebal' ) or 
    ( GetUnitTypeId(GetTriggerUnit()) == 'umtw' ) ) ) ) then
    endif
    return true
endfunction


Не нравица мне эта функция, как я пральна понемаю тут возвращается true...ведь в операторе if нету действий...

проще будет:
Код:
function Conditions takes nothing returns boolean
 return GetOwningPlayer(GetTriggerUnit())==Player(0) and (GetUnitTypeId(GetTriggerUnit())=='hmtt' or GetUnitTypeId(GetTriggerUnit())=='ocat' or GetUnitTypeId(GetTriggerUnit())=='ebal' or GetUnitTypeId(GetTriggerUnit())=='umtw')
endfunction

Отредактировано Integro, 04.01.2009 в 21:10.
Старый 04.01.2009, 21:04
Scorched

offline
Опыт: 7,912
Активность:
Цитата:
Не нравица мне эта функция, как я пральна понемаю тут возвращается true..

автор пытался оптимизировать, но сделал неправильно.
эту функцию надо привести к одной строчке вида return a and b or c or d.
не использовать эту CreateNUnitsAtLoc. да и много еще по мелочам

Scorched добавил:
опередели... =\
еще не юзать !=true и ==true, глаза режет
Старый 04.01.2009, 21:13
ELDAR
НИИ 4А-ВО кафедра SPELLS
offline
Опыт: 8,394
Активность:
Vampirrr соб-сно
CreateNUnitsAtLoc - отстой меняй на вот эту нативку
Код:
CreateUnitAtLoc         takes player id, integer unitid, location whichLocation, real face returns unit
Старый 04.01.2009, 21:22
Integro
старожило
offline
Опыт: 630
Активность:
Ну я думаю чтото вроде так:
Код:
function Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit())==Player(0) and (GetUnitTypeId(GetTriggerUnit())=='hmtt' or GetUnitTypeId(GetTriggerUnit())=='ocat' or GetUnitTypeId(GetTriggerUnit())=='ebal' or GetUnitTypeId(GetTriggerUnit())=='umtw')
endfunction

function Owner_Condition_Red takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit())==Player(0)
endfunction

function Owner_Condition_Blue takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit())==Player(1)
endfunction

function Actions takes nothing returns nothing
    local integer i=0
    local real x=GetUnitX(GetTriggerUnit())
    local real y=GetUnitY(GetTriggerUnit())
    local boolexpr b=Condition(function Owner_Condition_Red)
    local boolexpr b2=Condition(function Owner_Condition_Blue)
    loop
        set i = i+1
        exitwhen i > 8
        exitwhen RectContainsLoc(gg_rct_Board, Location(x,y+256*i))!=true
        exitwhen IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100,Location(x,y+256*i),b)!=true  
        if IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100,Location(x,y+256*i),b)==true   then
            if IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x,y+256*i),b2)==true then
                call CreateNUnitsAtLoc(1,'e001',GetTriggerPlayer(),Location(x,y+256*i),270) 
            else
                call CreateNUnitsAtLoc(1,'h000',GetTriggerPlayer(),Location(x,y+256*i),270) 
                exitwhen IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100,Location(x,y+256*i),b2)!=tru  e
               call CreateNUnitsAtLoc(1,'e001',GetTriggerPlayer(),Location(x,y+256*i),270) 
           endif
        endif
    endloop
    call DestroyBoolexpr(b)
    set b=null
    call DestroyBoolexpr(b2)
    set b2=null
endfunction


Толком небуду расбиратся, голова болит, уже...
Старый 04.01.2009, 21:24
Vampirrr
O_o
offline
Опыт: 19,286
Активность:
Integro, оно было в строчку, это я их так сместил, что б вам легче читать было) но к сожалению оно не работало как надо, поэтому сделал это:

Код:
function Conditions takes nothing returns boolean
    if ( not (GetOwningPlayer(GetTriggerUnit()) == Player(0) ) ) then
    return false
    endif
    if ( not ((GetUnitTypeId(GetTriggerUnit()) == 'hmtt' ) or ( GetUnitTypeId(GetTriggerUnit()) == 'ocat' ) or( GetUnitTypeId(GetTriggerUnit()) == 'ebal' ) or ( GetUnitTypeId(GetTriggerUnit()) == 'umtw' ) ) ) then
    return false
    endif
    return true
endfunction


Scorched, на что можно изменить CreateNUnitsAtLoc? (ответили уже))

И про утечки не забывайте)
Старый 04.01.2009, 21:24
Scorched

offline
Опыт: 7,912
Активность:
Vampirrr, с условиями сделай как Integro написал, +1 ему. ==true удаляй вообще (ибо не имеет смысла). а (выражение)!=true замени на not (выражение), так понтовее =)
Старый 04.01.2009, 21:41
Vampirrr
O_o
offline
Опыт: 19,286
Активность:
Integro, когда сделал это -

Код:
//----
local boolexpr b=Condition(function Owner_Condition_Red)
local boolexpr b2=Condition(function Owner_Condition_Blue)
//----
    loop
   //----
      exitwhen ( not ( IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), b)) == true ) ) 
      if (IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), b)) == true ) then
      if (IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), b2)) == true ) then
    //----
      exitwhen ( not ( IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), b2)) == true ) )
    //----
    endloop


матчинг стал срабатывать непаравильно и не создается юнита с ID 'h000' ..очень странно..
Condition +1

вот что имеем:
Код:
function Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit())==Player(0) and (GetUnitTypeId(GetTriggerUnit())=='hmtt' or GetUnitTypeId(GetTriggerUnit())=='ocat' or GetUnitTypeId(GetTriggerUnit())=='ebal' or GetUnitTypeId(GetTriggerUnit())=='umtw')
endfunction

function Owner_Condition_Red takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == Player(0) )
endfunction

function Owner_Condition_Blue takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == Player(1) )
endfunction

function Actions takes nothing returns nothing
local integer i
local real x = (GetUnitX(GetTriggerUnit())) 
local real y = (GetUnitY(GetTriggerUnit()))
set i = 0
    loop
    set i = i+1
    exitwhen i > 8
    exitwhen ( not (RectContainsLoc(gg_rct_Board, Location(x, y+256*i)) ))
      exitwhen ( not ( IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Red)))) ) 
      if (IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Red)))) then
      if (IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Blue)))) then
      call CreateUnitAtLoc(Player(0), 'e001', Location(x, y+256*i), 270 ) 
      else
      call CreateUnitAtLoc(Player(0), 'h000', Location(x, y+256*i), 270 ) 
      exitwhen ( not ( IsUnitGroupEmptyBJ(GetUnitsInRangeOfLocMatching(100.00, Location(x, y+256*i), Condition(function Owner_Condition_Blue)))) )
      call CreateUnitAtLoc(Player(0), 'e001', Location(x, y+256*i), 270 ) 
      endif
      endif
    endloop
endfunction

Отредактировано Vampirrr, 04.01.2009 в 22:15.
Старый 04.01.2009, 21:43
ShadoW DaemoN

offline
Опыт: 37,078
Активность:
Код:
globals
  group    temp_gr = CreateGroup()
  boolean  temp_b  = false
  boolexpr bx_red  = null
  boolexpr bx_blue = null
endglobals

function Conditions takes nothing returns boolean
  return GetOwningPlayer(GetTriggerUnit())==Player(0) and (GetUnitTypeId(GetTriggerUnit())=='hmtt' or GetUnitTypeId(GetTriggerUnit())=='ocat' or GetUnitTypeId(GetTriggerUnit())=='ebal' or GetUnitTypeId(GetTriggerUnit())=='umtw')
endfunction

function Owner_Condition_Red takes nothing returns boolean
  if GetOwningPlayer(GetFilterUnit()) == Player(0) then
    set temp_b = true
  endif
  return false
endfunction

function Owner_Condition_Blue takes nothing returns boolean
  if GetOwningPlayer(GetFilterUnit()) == Player(1) then
    set temp_b = true
  endif
  return false
endfunction

function Actions takes nothing returns nothing
  local integer i = 0
  local real x = GetUnitX(GetTriggerUnit())
  local real y = GetUnitY(GetTriggerUnit())
  local real z = y
  loop
    set i = i + 1
    set z = z + 256
    exitwhen i > 8 or not RectContainsCoords(gg_rct_Board, x, z)

    // ищем "красных" юнитов
    set temp_b = false
    call GroupEnumUnitsInRange(temp_gr, x, z, 100., bx_red)
    
    // если "красных" юнитов нет...
    if not temp_b then
      call GroupEnumUnitsInRange(temp_gr, x, z, 100., bx_blue)

      // если есть хотя бы 1 "синий" юнит...
      if temp_b then
        call CreateUnit(Player(0), 'h000', x, z, 270)
        set i = 8 // условие выхода из цикла
      endif
      
      // как я понял, этот юнит создается в любом случае, если нет красных юнитов
      call CreateUnit(Player(0), 'e001', x, z, 270)
    else
      set i = 8 // условие выхода из цикла
    endif
    
  endloop
endfunction

// --->>
  // initialization
  set bx_red  = Filter(function Owner_Condition_Red)
  set bx_blue = Filter(function Owner_Condition_Blue)
// <<---


Код стал более понятным, имхо.
Старый 05.01.2009, 09:28
Vampirrr
O_o
offline
Опыт: 19,286
Активность:
всем спс, темку закрыть)
Старый 08.01.2009, 18:58
Закрытая тема

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы можете скачивать файлы

BB-коды Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход



Часовой пояс GMT +3, время: 07:55.