wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 12-05-2008, 01:01 PM   #31
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

What if I needed to use real as a key? Please give me any suggestions how to get it working. If so, is it okay to use textmacro below?
Quote:
Originally Posted by Vexorian
Collapse Table:
    //Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks.
    //! textmacro Table__make takes name, type, key
    struct $name$ extends GTable

        method operator [] takes $type$ key returns integer
            return GetStoredInteger(gc,I2S(this),$key$)
        endmethod

        method operator []= takes $type$ key, integer value returns nothing
            call StoreInteger(gc,I2S(this),$key$, value)
        endmethod

        method flush takes $type$ key returns nothing
            call FlushStoredInteger(gc,I2S(this),$key$)
        endmethod

        method exists takes $type$ key returns boolean
            return HaveStoredInteger(gc,I2S(this),$key$)
        endmethod

    endstruct
    //! endtextmacro

Last edited by ToukoAozaki : 12-05-2008 at 01:01 PM.
ToukoAozaki is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 12-05-2008, 01:31 PM   #32
Pyrogasm
Lackadaisically Absent.
 
Pyrogasm's Avatar


Respected User
 
Join Date: Sep 2006
Posts: 4,514

Submissions (9)

Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)Pyrogasm is a splendid one to behold (638)

Hero Contest - Fourth place

Send a message via ICQ to Pyrogasm Send a message via AIM to Pyrogasm Send a message via MSN to Pyrogasm Send a message via Yahoo to Pyrogasm
Default

This would do it for you:
Collapse JASS:
//! runtextmacro Table__make("OtherTable", "real", "R2S(key)")
But as Anitarf pointed out, can't you just convert your reals to integers? Instead of using <Real Value> as a key, you could use I2R(<Real_Value>*100.00) or something.
__________________
Quote:
Originally posted by Rising_Dusk
Your spells are mostly ignored because they are not very cool so we aren't very excited to review/approve them, but you are incredibly persistent and won't give us an excuse to graveyard it. That is generally what results in a resource being ignored for a long time.

The Spell Request Thread Done for, unless someone else wants to revive it...
It lasted a damn long time.

Please; Ask for Help Appropriately














Quote:
Originally posted by Kyrbi0
Huh. Almost makes me wish I had a girlfriend, to take advantage of today (wait, no, that's not what I meant... I mean, take advantage of the fact that it is international women's day... gah, never mind).
Quote:
Originally posted by Pyrogasm
Rome may not have been built in a day, but the Romans sure as hell didn't say "look at this great city we built guys!" when they had nothing more than a bit of stone and some cottages.

Last edited by Pyrogasm : 12-05-2008 at 01:32 PM.
Pyrogasm is offline   Reply With Quote
Old 12-05-2008, 01:39 PM   #33
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Quote:
What if I needed to use real as a key?
I can't think of that as useful at all. What's this thing in which you want to use real as key?

Remember that reals are not accurate, so many different real values are the same data...
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 12-17-2008, 06:24 PM   #34
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

There is a typo error.
Quote:
private constant integer MAX_INSTANCES=8100
instead of
Code:
private constant integer MAX_INSTANCES=8190
Damn 9, it is so near the 0 on keyboard :)
__________________
Cool != Useful
Troll-Brain is offline   Reply With Quote
Old 12-17-2008, 07:40 PM   #35
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Well, it actually doesn't matter , if max instances is less than 8190,right now it considers it to be 8190.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 12-17-2008, 07:48 PM   #36
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

Quote:
Originally Posted by Vexorian
Well, it actually doesn't matter , if max instances is less than 8190,right now it considers it to be 8190.
Ofc , but it's still an error witch you can fix easily, so what ?
__________________
Cool != Useful
Troll-Brain is offline   Reply With Quote
Old 01-03-2009, 04:43 AM   #37
Blackroot
User
 
Join Date: Apr 2006
Posts: 260

Blackroot will become famous soon enough (40)Blackroot will become famous soon enough (40)

Spell Making Session 14 Winner

Default

Code:
library Table initializer init
    globals
        private constant integer MAX_INSTANCES=8100 //400000

        private gamecache gc
    endglobals

    private struct GTable[MAX_INSTANCES]
        method reset takes nothing returns nothing
            call FlushStoredMission(gc,I2S(this))
        endmethod

        private method onDestroy takes nothing returns nothing
            call FlushStoredMission(gc,I2S(this))
        endmethod
    endstruct

    //! textmacro Table__make takes name, type, key
    struct $name$ extends GTable

        method operator [] takes $type$ key returns integer
            return GetStoredInteger(gc,I2S(this),$key$)
        endmethod

        method operator []= takes $type$ key, integer value returns nothing
            call StoreInteger(gc,I2S(this),$key$, value)
        endmethod

        method flush takes $type$ key returns nothing
            call FlushStoredInteger(gc,I2S(this),$key$)
        endmethod

        method exists takes $type$ key returns boolean
            return HaveStoredInteger(gc,I2S(this),$key$)
        endmethod

    endstruct
    //! endtextmacro



    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction
    
    //! runtextmacro Table__make("Table","integer","I2S(key)" )
    //! runtextmacro Table__make("StringTable","string","key" )
    //! runtextmacro Table__make("HandleTable","handle","I2S(H2I(key))" )

    private function init takes nothing returns nothing
        call FlushGameCache(InitGameCache("libtable.gc"))
        set gc=InitGameCache("libtable.gc")
    endfunction
endlibrary

Woulden't it be more efficient to record I2S(this)?

Code:
struct Meh
 string i2s_this = I2S(this)

   //call StoreInteger(gc,i2s_this,$key$, value)
endstruct

That should at least slightly increase the speed of this code, no?

I'm also slightly confused as to the usage of this, for instant transfer code this should work flawlessly, but I dont see a way to instance this for delayed timers without H2I->I2S bugging. If so, globals would acheive the same effect? Obviously I am missing something.

Last edited by Blackroot : 01-03-2009 at 04:46 AM.
Blackroot is offline   Reply With Quote
Old 01-03-2009, 05:07 AM   #38
Here-b-Trollz
Corkscrew Chainsaw!!!
 
Join Date: Jun 2006
Posts: 711

Here-b-Trollz has a spectacular aura about (149)

Hero Contest #2 - 2nd Place

Default

Quote:
Originally Posted by Here-b-Trollz
Hmm, minimal but also possible... what about this?

Collapse JASS:
library Table initializer init
//***************************************************************
//* Table object
//* ------------
//*
//*   set t=Table.create() - instanceates a new table object
//*   call t.destroy()     - destroys it
//*   t[1234567]           - Get value for index 1234567
//*                          (zero if not assigned previously)
//*   set t[12341]=32      - Assigning it.
//*   call t.flush(12341)  - Flushes the stored value, so it
//*                          doesn't use any more memory
//*   call t.reset()       - Flushes the whole contents of the
//*                          Table.
//*   call t.destroy()     - Does reset() and also recycles the id.
//*
//*
//***************************************************************

//=============================================================
    globals
        private constant integer MAX_INSTANCES=400000

    //=========================================================
        private gamecache gc
    endglobals

    struct Table[MAX_INSTANCES]
        private string index=I2S(this)
        method operator [] takes integer key returns integer
            return GetStoredInteger(gc,.index,I2S(key))
        endmethod

        method operator []= takes integer key, integer value returns nothing
            call StoreInteger(gc,.index,I2S(key), value)
        endmethod

        method flush takes integer key returns nothing
            call FlushStoredInteger(gc,.index,I2S(key))
        endmethod

        method reset takes nothing returns nothing
            call FlushStoredMission(gc,.index)
        endmethod

        private method onDestroy takes nothing returns nothing
            call FlushStoredMission(gc,.index)
        endmethod
    endstruct


    private function init takes nothing returns nothing
        call FlushGameCache(InitGameCache("libtable.gc"))
        set gc=InitGameCache("libtable.gc")
    endfunction
endlibrary

Seems to work for me, and it saves a function call. Although... i suppose it would depend on whether or not your table indexes go up past one array's worth.

The answer is, if you have less than 8190 Tables max, then it MIGHT be faster. If array lookup is faster than I2S(), than yeah, it'd be practical. But this way, if we go up to 400000, it's still not an issue.

EDIT: The point is, for instance:

Collapse JASS:
globals
    HandleTable Kills
endglobals

function GetUnitKills takes unit u returns integer
    return Kills[u]
endfunction

Or even:

Collapse JASS:
struct Data
    HandleTable storage

    integer kills
    integer deaths

    static method operator [] takes unit u returns Data
        return .storage[u]
    endmethod
endstruct

It also serves as an awesome array for integers with no limits on indexes = storing stuff under object type ids just got a hell of a lot easier.
__________________
By reading this signature, you agree that I cannot be held accountable for anything that I might say or do.

Last edited by Here-b-Trollz : 01-03-2009 at 05:11 AM.
Here-b-Trollz is offline   Reply With Quote
Old 01-03-2009, 07:06 AM   #39
Blackroot
User
 
Join Date: Apr 2006
Posts: 260

Blackroot will become famous soon enough (40)Blackroot will become famous soon enough (40)

Spell Making Session 14 Winner

Default

Ah, so it still requires the use of H2I to store handles . Still, this would seem like a fantastic script to store equipment systems in or the likes.

-
I'm fairly sure for a small index value (Or perhaps for any index value < 8191 in this case) warcrafts index system should be faster than large INT->string conversions (What is a handle - 12-13 digits?) - I could be wrong, though.
Blackroot is offline   Reply With Quote
Old 01-03-2009, 12:36 PM   #40
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

H2I truly is safe and is really the only way to make something that works for all handles.


Quote:
I'm fairly sure for a small index value (Or perhaps for any index value < 8191 in this case) warcrafts index system should be faster than large INT->string conversions
Any other known fact that you feel like posting?
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 01-03-2009, 01:53 PM   #41
chobibo
100% Genuine Retard!
 
chobibo's Avatar
 
Join Date: Jan 2007
Posts: 797

chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)

Send a message via Yahoo to chobibo
Default

Quote:
Originally Posted by Blackroot
Ah, so it still requires the use of H2I to store handles

Most storage systems use HandleToInteger conversions, you can avoid it by searching for data linearly, for units, you can use custom values, but indexing units is hard work.
__________________
Where's mah sig?
chobibo is offline   Reply With Quote
Old 01-04-2009, 12:44 AM   #42
Blackroot
User
 
Join Date: Apr 2006
Posts: 260

Blackroot will become famous soon enough (40)Blackroot will become famous soon enough (40)

Spell Making Session 14 Winner

Default

Quote:
Any other known fact that you feel like posting?
The square root of 25 is 5!

It can't be that indexing is so slow a conversion takes place faster. I'll benchmark it, just because I don't beileive that's possible!

[edit]
...Yes um:

Accessing array value 8190/8190: ~655 Exec/MS
Converting '0000' -> string: ~1633 Exec/MS

Accessing array value 0/8190: ~683 Exec/MS
Converting '0000' -> string: ~1700 Exec/MS

Converting 'ZZZZ' -> string: ~1600 Exec/MS


Touche.

Last edited by Blackroot : 01-04-2009 at 01:00 AM.
Blackroot is offline   Reply With Quote
Old 01-04-2009, 04:32 AM   #43
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Ok...

... How about you now test the speed differences between the + operator and a call to GetHeroStr?
Vexorian is offline   Reply With Quote
Old 01-04-2009, 05:37 AM   #44
Blackroot
User
 
Join Date: Apr 2006
Posts: 260

Blackroot will become famous soon enough (40)Blackroot will become famous soon enough (40)

Spell Making Session 14 Winner

Default

Quote:
Originally Posted by Vexorian
Ok...

... How about you now test the speed differences between the + operator and a call to GetHeroStr?

Mmm some interesting results:

Integral Addition: 1,000,000 Exec / MS

GetHeroStr: 4000 Exec / MS

Division of integers: 1,000,000 Exec/MS
Multiplication of integes: 1,000,000 Exec/Ms

Interestingly enough:

Substraction of reals: 60,000 Exec/MS
Addition of reals: 1,000,000 Exec/MS

I think the results clearly show that using addition is far superior than trying to use natives. I don't know about you, but I'm woring on switching my entire batch of systems to use only addition with these amazing new results.
Blackroot is offline   Reply With Quote
Old 01-04-2009, 04:40 PM   #45
chobibo
100% Genuine Retard!
 
chobibo's Avatar
 
Join Date: Jan 2007
Posts: 797

chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)

Send a message via Yahoo to chobibo
Default

Quote:
Originally Posted by Blackroot
I'm fairly sure for a small index value (Or perhaps for any index value < 8191 in this case) warcrafts index system should be faster than large INT->string conversions (What is a handle - 12-13 digits?) - I could be wrong, though.

What indexing system?
__________________
Where's mah sig?
chobibo is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 02:25 PM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services