System Handle Typecasting

Romek

Super Moderator
Reaction score
963
I really dislike your coding standards.. With the overkill credits and the crappy 2-lined library.

This whole thing could be done using textmacros.

Why is the example using a stub method?

> except for triggers, those aren't destroyed
... o_O

You do realise your example won't work, as the structs are public. So a Htn_ prefix is required.
Struct members and methods are public by default, so 'public' keyword isn't needed.

This isn't even typecasting handles by the way. Just structs.
 

Nestharus

o-o
Reaction score
84
You do realise your example won't work, as the structs are public. So a Htn_ prefix is required.
Struct members and methods are public by default, so 'public' keyword isn't needed.
It's simply an example of how this might be used...

This whole thing could be done using textmacros.
That is true, I didn't think about that =). My mind was elsewhere while I was making this =).

I really dislike your coding standards.. With the overkill credits and the crappy 2-lined library.
There is a very serious point to those 2 lined libraries o-o.

maybe make the handles delegates?
I'll look into it and see maybe what I could do with them. The idea of just having a handle, setting it's type, and then manipulating it sounds pretty good. I didn't think about it, but I'm not sure how I would do it with how I'm using it at the moment.

This is an interface called Handle within a system called Spawn
JASS:
public interface Handle
            public integer h
            public hashtable memory
            
            public method getX takes nothing returns real defaults 0.0
            public method getY takes nothing returns real defaults 0.0
            public method getPlayer takes nothing returns player defaults null
            public method getTypeId takes nothing returns integer defaults 0
            public method getLife takes nothing returns real defaults 0.0
            public method getLevel takes nothing returns integer defaults 0
            public method getXP takes nothing returns integer defaults 0
            public method getFacing takes nothing returns real defaults 0.0
            
            public method setPosition takes real x, real y returns nothing defaults nothing
            public method setPlayer takes player p returns nothing defaults nothing
            public method setTypeId takes integer t returns nothing defaults nothing
            public method setLife takes real x returns nothing defaults nothing
            public method setLevel takes integer x returns nothing defaults nothing
            public method setXP takes integer x returns nothing defaults nothing
            public method setFacing takes real x returns nothing defaults nothing
            
            public static method create takes nothing
            
            public method make takes player p, integer typeId, real x, real y, real facing returns nothing defaults nothing
            public method getHandleId takes nothing returns integer defaults 0
        endinterface


As you can see, Spawn has very specific properties for handles. These properties have to be within the interface, otherwise it can't access a struct of an unknown type (allows people to define their own handles, artificially do things on handles, w/e).

Example-
JASS:
public struct Unit extends Handle
            public integer h
            public hashtable memory
            
            public method make takes player p, integer typeId, real x, real y, real facing returns nothing
                set .h = Htn_Unit.create(CreateUnit(p, typeId, x, y, facing))
                call SaveInteger(memory, Hcn_HANDLE, GetHandleId((Htn_Unit(.h).h)), this)
            endmethod
            
            public method getX takes nothing returns real
                return GetUnitX((Htn_Unit(.h).h))
            endmethod
            
            public method getY takes nothing returns real
                return GetUnitY((Htn_Unit(.h).h))
            endmethod
            
            public method getPlayer takes nothing returns player
                return GetOwningPlayer((Htn_Unit(.h).h))
            endmethod
            
            public method getTypeId takes nothing returns integer
                return GetUnitTypeId((Htn_Unit(.h).h))
            endmethod
            
            public method getLevel takes nothing returns integer
                return GetUnitLevel((Htn_Unit(.h).h))
            endmethod
            
            public method getXP takes nothing returns integer
                return GetHeroXP((Htn_Unit(.h).h))
            endmethod
            
            public method getHandleId takes nothing returns integer
                return GetHandleId((Htn_Unit(.h).h))
            endmethod
            
            public method getFacing takes nothing returns real
                return GetUnitFacing((Htn_Unit(.h).h))
            endmethod
            
            public method setPosition takes real x, real y returns nothing
                call SetUnitPosition((Htn_Unit(.h).h), x, y)
            endmethod
            
            public method setPlayer takes player p returns nothing
                call SetUnitOwner((Htn_Unit(.h).h), p, false)
            endmethod
            
            public method setLevel takes integer x returns nothing
                call SetHeroLevel((Htn_Unit(.h).h), x, false)
            endmethod
            
            public method setXP takes integer x returns nothing
                call SetHeroXP((Htn_Unit(.h).h), x, false)
            endmethod
            
            public method setFacing takes real x returns nothing
                call SetUnitFacing((Htn_Unit(.h).h), x)
            endmethod
            
            public static method create takes nothing returns thistype
                local thistype u = thistype.allocate()
                return u
            endmethod
        endstruct


This is a pre-defined handle type in Spawn called Unit. See how it uses the library to quickly typecast the handle. The library acts more like containers for handles than anything. They are stored in structs for the quick typecasting.

Now, another way I could format this library is 2 sets of arrays (one for type ids of handles and the other to store the handles) which is what the structs do for me. Also, I could do a hashtable, but that would probably slow it down =).

Really, I think how it is right now is fine (change to macro probably), but maybe if you clarify more on what you were thinking that'd hopefully lower its enormous size, I'd be happy to listen :D
 

Nestharus

o-o
Reaction score
84
Are you making extra bj?

Please read what this is... it's a library

The only use I can see for this is slowing down everything in WC3.

I think you missed the boat a bit. Speed and functionality are generally important, whilst convention and credit notes are generally not too worried about.

I showed a use in the first post...
 

Romek

Super Moderator
Reaction score
963
GY'd this and the framework.
 

Nestharus

o-o
Reaction score
84
I lol'ed.
Hashing will faster than this?
I think the "Handle Wrapper" is better name.

Probably...

I'm going to be updating it eventually as a set of text macros for private use or w/e in various thingies ^_-.

It's sad people don't find this useful : \, but it's a major requirement for some of the stuff I'm doing.

Then again, mods here called my loops junk when after 200 million iterations they still register 0 on a timer running next to them.

So w/e =P
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top