Добавлен
Мне нужно преобразовать real в integer так, чтобы каждый real имел свой integer (как у функции GetHandleId( ), только вместо handle должен быть real). Нативная функция R2I( ) может вернуть одно и то же значение для разных real'ов ( R2I( 0.01 ) == R2I( 0.02 ) ).

Попробовал умножать real на 10 000 000, так, например, GetRealId( 0.03125 ) == 312500, но так можно упереться в потолок 2147483647
function GetRealId takes real whichReal returns integer
	return ( whichReal * 10000000 )
endfunction

В мемхаке нашел следующую функцию, но хотелось бы, чтобы функция работала без return bug'a
раскрыть
//# +nosemanticerror
    function realToIndex takes real r returns integer
        loop
            return r
        endloop
        return 0
    endfunction

    function cleanInt takes integer i returns integer
        return i
    endfunction

    function mR2I takes real r returns integer
        return cleanInt( realToIndex( r ) )
    endfunction
Можно сократить до (вроде работает):
//# +nosemanticerror
    function R2IEx takes real r returns integer
        loop
            return r
        endloop
        return 0
    endfunction

Принятый ответ

Сделал следующим образом:
раскрыть
	function interface callback takes integer this returns nothing defaults nothing


    struct linkedList

        private static timer    period      = null
        private        real     curTimeout
        private        real     timeout
        private        thistype prev
        private        thistype next
        private        callback handlerFunc


		static constant method operator listPeriod takes nothing returns real
            return 0.01
        endmethod


        method destroy takes nothing returns nothing
            set this.prev.next = this.next
            set this.next.prev = this.prev

            if (thistype(0).next == thistype(0)) then
                call PauseTimer(this.period)
            endif

            call thistype.deallocate(this)
        endmethod


        private static method iterate takes nothing returns nothing
            local thistype this = thistype(0).next

            loop
                exitwhen (this == thistype(0))

                set this.curTimeout = this.curTimeout + thistype.listPeriod

                if (this.curTimeout >= this.timeout) then
                    set this.curTimeout = 0.0
                    call this.handlerFunc.evaluate(integer(this))
                endif

                set this = this.next
            endloop
        endmethod


        static method create takes real timeout, callback handlerFunc returns thistype
            local thistype this = thistype.allocate()

            set this.next        = thistype(0)
            set this.prev        = thistype(0).prev
            set this.next.prev   = this
            set this.prev.next   = this
            set this.timeout     = timeout
            set this.curTimeout  = 0.0
            set this.handlerFunc = handlerFunc

            if (thistype.period == null) then
                set thistype.period = CreateTimerEx()
            endif

            if (this.prev == thistype(0)) then
                call TimerStart(thistype.period, thistype.listPeriod, true, function thistype.iterate)
            endif

            return this
        endmethod


    endstruct
Будет ли это создавать большую нагрузку на игру из-за низкого периода таймера, несмотря на то, что таймер хоть и работает с низкой частотой, он ничего толком то и не делает, кроме арифметических вычислений?
`
ОЖИДАНИЕ РЕКЛАМЫ...

Показан только небольшой набор комментариев вокруг указанного. Перейти к актуальным.
0
10
6 лет назад
Отредактирован LordDracula
0
//# +nosemanticerror
перед функцией надо добавить и pjass для мемхака
0
29
6 лет назад
0
Иными словами, ты хочешь, чтобы множество R было равномощно множеству N? Это невозможно, т.к. N счётно, а R несчётно.
Нормально вы тут рофлите, а то, что мы тут не в вакууме работаем, а на реальном компьютере и флоаты записываютя в те же 32/64 бита ничего?
Полагаю необходима функция типа docs.oracle.com/javase/7/docs/api/java/lang/Float.html#floatToIn... о чем наверное и говорит драколич
0
18
6 лет назад
Отредактирован Hodor
0
LordDracula
хм
novjass вообще текст убирает из конечной карты, надо пошаманить
А так, варкрафт это должен без ошибок читать, не понимаю почему pjass считает это за ошибку
Загруженные файлы
0
21
6 лет назад
Отредактирован scopterectus
0
Сделал следующим образом:
раскрыть
	function interface callback takes integer this returns nothing defaults nothing


    struct linkedList

        private static timer    period      = null
        private        real     curTimeout
        private        real     timeout
        private        thistype prev
        private        thistype next
        private        callback handlerFunc


		static constant method operator listPeriod takes nothing returns real
            return 0.01
        endmethod


        method destroy takes nothing returns nothing
            set this.prev.next = this.next
            set this.next.prev = this.prev

            if (thistype(0).next == thistype(0)) then
                call PauseTimer(this.period)
            endif

            call thistype.deallocate(this)
        endmethod


        private static method iterate takes nothing returns nothing
            local thistype this = thistype(0).next

            loop
                exitwhen (this == thistype(0))

                set this.curTimeout = this.curTimeout + thistype.listPeriod

                if (this.curTimeout >= this.timeout) then
                    set this.curTimeout = 0.0
                    call this.handlerFunc.evaluate(integer(this))
                endif

                set this = this.next
            endloop
        endmethod


        static method create takes real timeout, callback handlerFunc returns thistype
            local thistype this = thistype.allocate()

            set this.next        = thistype(0)
            set this.prev        = thistype(0).prev
            set this.next.prev   = this
            set this.prev.next   = this
            set this.timeout     = timeout
            set this.curTimeout  = 0.0
            set this.handlerFunc = handlerFunc

            if (thistype.period == null) then
                set thistype.period = CreateTimerEx()
            endif

            if (this.prev == thistype(0)) then
                call TimerStart(thistype.period, thistype.listPeriod, true, function thistype.iterate)
            endif

            return this
        endmethod


    endstruct
Будет ли это создавать большую нагрузку на игру из-за низкого периода таймера, несмотря на то, что таймер хоть и работает с низкой частотой, он ничего толком то и не делает, кроме арифметических вычислений?
Принятый ответ
0
28
6 лет назад
0
В мемхаке нашел следующую функцию, но хотелось бы, чтобы функция работала без return bug'a
Это не мемхак, это return-loop hack, работает он исправно, ничего не сломает. Про разные ответы на одно и тоже число я уже ответил, Jass ошибается при чтении чисел с 10 и более знаков после запятой. Иногда он ошибается и при чтении чисел с меньшим количеством знаков.

Что же касается твоего решения, я немного не понял, как это относится к вопросу.
0
21
6 лет назад
0
PT153, Я не имел ввиду, что это мемхак, а то что функцию я брал из библиотеки Typecast, которая прилагается к мемхаку.
Чтобы понять это, придётся прочитать всё вышенаписанное.
Показан только небольшой набор комментариев вокруг указанного. Перейти к актуальным.
Чтобы оставить комментарий, пожалуйста, войдите на сайт.