• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

ggvars

Status
Not open for further replies.
Level 13
Joined
Nov 7, 2014
Messages
571
ggvars - listings of the "generated global"? variables used by WE

JASS:
//! novjass

ggvars - listings of the "generated global"? variables used by WE

Description:

    WorldEditor (WE) has tools for editing different types of objects. For example the
    Tool Palette has a Regions tab that lists all the regions the map uses and allows
    one to quickly locate and edit the regions. When the map is compiled WE generates
    and initializes global variables that would represent these objects in-game.

    The ggvars library fills arrays with the values of these generated variables.

    For example if the map has 3 regions in the Region tab:
        Region 000
        Region 001
        Region 002

    WE would generate the following variables:
        rect gg_rct_Region_000 = null
        rect gg_rct_Region_001 = null
        rect gg_rct_Region_002 = null

    and initilialize them with:
        function CreateRegions takes nothing returns nothing
            set gg_rct_Region_000=Rect(576.0, - 384.0, 800.0, 192.0)
            set gg_rct_Region_001=Rect(128.0, - 736.0, 576.0, - 384.0)
            set gg_rct_Region_002=Rect(704.0, 384.0, 768.0, 768.0)
        endfunction

    the array that would hold these regions/rects is called:
        region_vars

    the region_vars (and all other arrays filled by ggvars) is a 1 based array:
        region_vars[1] == gg_rct_Region_000
        region_vars[2] == gg_rct_Region_001
        region_vars[3] == gg_rct_Region_002

    the number of regions in the array is stored in the variable:
        region_vars_count = 3

    2 additional arrays are also filled:
        region_vars_name[1] == "gg_rct_Region_000"
        region_vars_name[2] == "gg_rct_Region_001"
        region_vars_name[3] == "gg_rct_Region_002"

        region_vars_name_stid[1] == stid_from_handle("gg_rct_Region_000")
        region_vars_name_stid[2] == stid_from_handle("gg_rct_Region_001")
        region_vars_name_stid[3] == stid_from_handle("gg_rct_Region_002")


Types and names of the filled arrays:

    rect array region_vars
    unit array unit_vars
    destructable array destructable_vars
    trigger array trigger_vars
    sound array sound_vars
    camerasetup array camera_vars
    item array item_vars


Notes:
    Because the filling of the arrays requires scanning, which I guess could be slow
    depending on number of variables in the map, you can disable which arrays get filled
    with the Use_*_Vars configuration constants.


//! endnovjass

library ggvars initializer scan uses BytecodeBoilerplate

globals
    private constant boolean Use_Region_Vars = true
    private constant boolean Use_Unit_Vars = true
    private constant boolean Use_Destructable_Vars = true
    private constant boolean Use_Trigger_Vars = true
    private constant boolean Use_Sound_Vars = true
    private constant boolean Use_Camera_Vars = true
    private constant boolean Use_Item_Vars = true

    private constant integer Scan_Iterations_Per_Exec = 500 // some value with which we don't hit the op-limit
    private constant integer String_Table_Start_Offset = 0xF7B // adjust if using modified common.j and/or blizzard.j
    private integer String_Table_End_Offset
    private integer ef_offset

    // the Region Palette's regions are converted to global variables
    // of type rect that have names beginning with "gg_rct_"
    //
    rect array region_vars
    string array region_vars_name
    integer array region_vars_name_stid
    integer region_vars_count = 0

    unit array unit_vars
    string array unit_vars_name
    integer array unit_vars_name_stid
    integer unit_vars_count = 0

    destructable array destructable_vars
    string array destructable_vars_name
    integer array destructable_vars_name_stid
    integer destructable_vars_count = 0

    trigger array trigger_vars
    string array trigger_vars_name
    integer array trigger_vars_name_stid
    integer trigger_vars_count = 0

    sound array sound_vars
    string array sound_vars_name
    integer array sound_vars_name_stid
    integer sound_vars_count = 0

    camerasetup array camera_vars
    string array camera_vars_name
    integer array camera_vars_name_stid
    integer camera_vars_count = 0

    item array item_vars
    string array item_vars_name
    integer array item_vars_name_stid
    integer item_vars_count = 0
endglobals

globals
    private integer array bc
    private code bc_code

    private handle result_handle = null
    private integer result_handle_stid
endglobals

private function init takes nothing returns nothing
    set String_Table_End_Offset = stid_from_handle(I2SH(2))

    set bc[8190] = 0
    set bc_code = I2C(Memory[get_array_struct_from_name(SCOPE_PRIVATE + "bc")/4 + 12/4])

    set result_handle_stid = stid_from_handle(SCOPE_PRIVATE + "result_handle")
endfunction

private function call_bc takes integer i returns nothing
    set bc[0] = 0x0E010700
    set bc[1] = i
    set bc[2] = 0x11010000
    set bc[3] = result_handle_stid
    set bc[4] = 0x27000000
    set bc[5] = 0x00000000
    call ForForce(bj_FORCE_PLAYER[0], bc_code)
endfunction

globals
    // these are not used but are needed to fool jasshelper
    handle gg_vars_typecast_handle
    rect gg_vars_typecast_region
    unit gg_vars_typecast_unit
    destructable gg_vars_typecast_destructable
    trigger gg_vars_typecast_trigger
    sound gg_vars_typecast_sound
    camerasetup gg_vars_typecast_camerasetup
    item gg_vars_typecast_item

    handle l__gg_vars_typecast_handle
    rect l__gg_vars_typecast_region
    unit l__gg_vars_typecast_unit
    destructable l__gg_vars_typecast_destructable
    trigger l__gg_vars_typecast_trigger
    sound l__gg_vars_typecast_sound
    camerasetup l__gg_vars_typecast_camerasetup
    item l__gg_vars_typecast_item
endglobals

private function set_handle takes handle h returns nothing
    set l__gg_vars_typecast_handle = h
    return // prevent jasshelper from inlining this function
endfunction

private function typecast1 takes nothing returns nothing
    local handle gg_vars_typecast_region // jasshelper will implicitly rename this to l__gg_vars_typecast_region
    local rect gg_vars_typecast_handle // jasshelper will implicitly rename this to l__gg_vars_typecast_handle
endfunction
//# +nosemanticerror
public function handle_to_rect takes handle h returns rect
    call set_handle(h)
    return l__gg_vars_typecast_handle
endfunction

private function typecast2 takes nothing returns nothing
    local handle gg_vars_typecast_destructable
    local destructable gg_vars_typecast_handle
endfunction
//# +nosemanticerror
public function handle_to_destructable takes handle h returns destructable
    call set_handle(h)
    return l__gg_vars_typecast_handle
endfunction

private function typecast3 takes nothing returns nothing
    local handle gg_vars_typecast_unit
    local unit gg_vars_typecast_handle
endfunction
//# +nosemanticerror
public function handle_to_unit takes handle h returns unit
    call set_handle(h)
    return l__gg_vars_typecast_handle
endfunction

private function typecast4 takes nothing returns nothing
    local handle gg_vars_typecast_trigger
    local trigger gg_vars_typecast_handle
endfunction
//# +nosemanticerror
public function handle_to_trigger takes handle h returns trigger
    call set_handle(h)
    return l__gg_vars_typecast_handle
endfunction

private function typecast5 takes nothing returns nothing
    local handle gg_vars_typecast_sound
    local sound gg_vars_typecast_handle
endfunction
//# +nosemanticerror
public function handle_to_sound takes handle h returns sound
    call set_handle(h)
    return l__gg_vars_typecast_handle
endfunction

private function typecast6 takes nothing returns nothing
    local handle gg_vars_typecast_camerasetup
    local camerasetup gg_vars_typecast_handle
endfunction
//# +nosemanticerror
public function handle_to_camerasetup takes handle h returns camerasetup
    call set_handle(h)
    return l__gg_vars_typecast_handle
endfunction

private function typecast7 takes nothing returns nothing
    local handle gg_vars_typecast_item
    local item gg_vars_typecast_handle
endfunction
//# +nosemanticerror
public function handle_to_item takes handle h returns item
    call set_handle(h)
    return l__gg_vars_typecast_handle
endfunction

private function scan_exec takes nothing returns nothing
    local integer i
    local integer j
    local string s

    set i = ef_offset
    set j = ef_offset + Scan_Iterations_Per_Exec
    loop
        exitwhen i > String_Table_End_Offset
        exitwhen i > j

        set s = ReadStringFromId(i)

        if false then

        // can't have jass-elseif in static ifs?

        elseif SubString(s, 0, 7) == "gg_rct_" and s != "gg_rct_" then
static if Use_Region_Vars then
            set region_vars_count = region_vars_count + 1
            set region_vars_name_stid[region_vars_count] = i
            set region_vars_name[region_vars_count] = s
            call call_bc(i)
            set region_vars[region_vars_count] = handle_to_rect(result_handle)

endif

        elseif SubString(s, 0, 8) == "gg_unit_" and s != "gg_unit_" then
static if Use_Unit_Vars then
            set unit_vars_count = unit_vars_count + 1
            set unit_vars_name_stid[unit_vars_count] = i
            set unit_vars_name[unit_vars_count] = s
            call call_bc(i)
            set unit_vars[unit_vars_count] = handle_to_unit(result_handle)

endif

        elseif SubString(s, 0, 8) == "gg_dest_" and s != "gg_dest_" then
static if Use_Destructable_Vars then
            set destructable_vars_count = destructable_vars_count + 1
            set destructable_vars_name_stid[destructable_vars_count] = i
            set destructable_vars_name[destructable_vars_count] = s
            call call_bc(i)
            set destructable_vars[destructable_vars_count] = handle_to_destructable(result_handle)

endif

        elseif SubString(s, 0, 7) == "gg_trg_" and s != "gg_trg_" then
static if Use_Trigger_Vars then
            set trigger_vars_count = trigger_vars_count + 1
            set trigger_vars_name_stid[trigger_vars_count] = i
            set trigger_vars_name[trigger_vars_count] = s
            call call_bc(i)
            set trigger_vars[trigger_vars_count] = handle_to_trigger(result_handle)

endif

        elseif SubString(s, 0, 7) == "gg_snd_" and s != "gg_snd_" then
static if Use_Sound_Vars then
            set sound_vars_count = sound_vars_count + 1
            set sound_vars_name_stid[sound_vars_count] = i
            set sound_vars_name[sound_vars_count] = s
            call call_bc(i)
            set sound_vars[sound_vars_count] = handle_to_sound(result_handle)

endif

        elseif SubString(s, 0, 7) == "gg_cam_" and s != "gg_cam_" then
static if Use_Camera_Vars then
            set camera_vars_count = camera_vars_count + 1
            set camera_vars_name_stid[camera_vars_count] = i
            set camera_vars_name[camera_vars_count] = s
            call call_bc(i)
            set camera_vars[camera_vars_count] = handle_to_camerasetup(result_handle)

endif

        elseif SubString(s, 0, 8) == "gg_item_" and s != "gg_item_" then
static if Use_Item_Vars then
            set item_vars_count = item_vars_count + 1
            set item_vars_name_stid[item_vars_count] = i
            set item_vars_name[item_vars_count] = s
            call call_bc(i)
            set item_vars[item_vars_count] = handle_to_item(result_handle)

endif

        endif

        set i = i + 1
    endloop
    set ef_offset = i
endfunction

private function scan takes nothing returns nothing
    local integer i
    local rect r

    call init()

    set ef_offset = String_Table_Start_Offset
    loop
        exitwhen ef_offset > String_Table_End_Offset
        call ForForce(bj_FORCE_PLAYER[0], function scan_exec)
    endloop
endfunction

endlibrary
 

Attachments

  • bytecode-boilerplate.j
    10.3 KB · Views: 37
Status
Not open for further replies.
Top