More efficient way to call global scripts.

This commit is contained in:
Martin Haye 2015-12-31 09:56:50 -08:00
parent 9a1a1d0a0e
commit 55cd9892e3
4 changed files with 34 additions and 49 deletions

View File

@ -391,6 +391,9 @@ def startCombat()
// Display portrait of first group
setPortrait(global=>p_enemyGroups=>p_enemies->ba_images[0])
// If portrait was already in memory, the memory mgr load might still be open. Close it.
mmgr(FINISH_LOAD, 0)
// We're going to do all our text drawing in window 2. Also, might as well
// set everything up so that the map gets redrawn when combat finishes.
setWindow2()

View File

@ -1851,7 +1851,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
def testCombat()
word globalScripts, callScript
word globalScripts
word combatEngine
word x, y
byte dir
@ -1865,16 +1865,15 @@ def testCombat()
combatEngine = mmgr(QUEUE_LOAD, MODULE_COMBAT<<8 | RES_TYPE_MODULE)
globalScripts = mmgr(QUEUE_LOAD, MODULE_GLOBAL_SCRIPTS<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 1) // 1 = keep open
callScript = globalScripts()
// Create the enemy group(s).
global=>p_enemyGroups = NULL
when rand16() % 2
is 0
addToList(@global=>p_enemyGroups, callScript(script_new_EnemyGroup_Dirt_Bags))
addToList(@global=>p_enemyGroups, globalScripts()=>script_new_EnemyGroup_Dirt_Bags())
break
otherwise
addToList(@global=>p_enemyGroups, callScript(script_new_EnemyGroup_Flesh_Feeders))
addToList(@global=>p_enemyGroups, globalScripts()=>script_new_EnemyGroup_Flesh_Feeders())
break
wend
@ -2038,16 +2037,11 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Create the party
def initParty()
word globalScripts, callScript
word globalScripts
globalScripts = mmgr(QUEUE_LOAD, MODULE_GLOBAL_SCRIPTS<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 1) // 1 = keep open
callScript = globalScripts()
addToList(@global=>p_players, callScript(script_new_Player_Hue_Hauser))
addToList(@global=>p_players, callScript(script_new_Player_Mokahnu))
// No need for the global scripts now that everything has been created
addToList(@global=>p_players, globalScripts()=>script_new_Player_Hue_Hauser())
addToList(@global=>p_players, globalScripts()=>script_new_Player_Mokahnu())
mmgr(FREE_MEMORY, globalScripts)
end

View File

@ -12,6 +12,16 @@ include "gamelib.plh"
include "playtype.plh"
include "gen_images.plh"
predef new_Modifier, new_Armor_Chaps, new_Armor_ShamanHeaddress, new_Armor_TahnkuPants, new_Armor_TahnkuVest
predef new_Weapon_Handgun, new_Weapon_SpiritBow, new_Weapon_SpiritBlade, calcPlayerArmor, new_Player_Hue_Hauser
predef new_Player_Mokahnu, new_Enemy_Dirt_Bag, new_EnemyGroup_Dirt_Bags, new_Enemy_Flesh_Feeder
predef new_EnemyGroup_Flesh_Feeders
word[] funcTbl = @new_Modifier, @new_Armor_Chaps, @new_Armor_ShamanHeaddress, @new_Armor_TahnkuPants, @new_Armor_TahnkuVest
word = @new_Weapon_Handgun, @new_Weapon_SpiritBow, @new_Weapon_SpiritBlade, @calcPlayerArmor, @new_Player_Hue_Hauser
word = @new_Player_Mokahnu, @new_Enemy_Dirt_Bag, @new_EnemyGroup_Dirt_Bags, @new_Enemy_Flesh_Feeder
word = @new_EnemyGroup_Flesh_Feeders
///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Modifier(kind, value)
word p
@ -296,27 +306,5 @@ def new_EnemyGroup_Flesh_Feeders
return p
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def callGlobalScript(n)
when n
is 0; return new_Modifier()
is 1; return new_Armor_Chaps()
is 2; return new_Armor_ShamanHeaddress()
is 3; return new_Armor_TahnkuPants()
is 4; return new_Armor_TahnkuVest()
is 5; return new_Weapon_Handgun()
is 6; return new_Weapon_SpiritBow()
is 7; return new_Weapon_SpiritBlade()
is 8; return calcPlayerArmor()
is 9; return new_Player_Hue_Hauser()
is 10; return new_Player_Mokahnu()
is 11; return new_Enemy_Dirt_Bag()
is 12; return new_EnemyGroup_Dirt_Bags()
is 13; return new_Enemy_Flesh_Feeder()
is 14; return new_EnemyGroup_Flesh_Feeders()
otherwise; brk()
wend
end
return @callGlobalScript
return @funcTbl
done

View File

@ -9,17 +9,17 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
const script_new_Modifier = 0
const script_new_Armor_Chaps = 1
const script_new_Armor_ShamanHeaddress = 2
const script_new_Armor_TahnkuPants = 3
const script_new_Armor_TahnkuVest = 4
const script_new_Weapon_Handgun = 5
const script_new_Weapon_SpiritBow = 6
const script_new_Weapon_SpiritBlade = 7
const script_calcPlayerArmor = 8
const script_new_Player_Hue_Hauser = 9
const script_new_Player_Mokahnu = 10
const script_new_Enemy_Dirt_Bag = 11
const script_new_EnemyGroup_Dirt_Bags = 12
const script_new_Enemy_Flesh_Feeder = 13
const script_new_EnemyGroup_Flesh_Feeders = 14
const script_new_Armor_Chaps = 2
const script_new_Armor_ShamanHeaddress = 4
const script_new_Armor_TahnkuPants = 6
const script_new_Armor_TahnkuVest = 8
const script_new_Weapon_Handgun = 10
const script_new_Weapon_SpiritBow = 12
const script_new_Weapon_SpiritBlade = 14
const script_calcPlayerArmor = 16
const script_new_Player_Hue_Hauser = 18
const script_new_Player_Mokahnu = 20
const script_new_Enemy_Dirt_Bag = 22
const script_new_EnemyGroup_Dirt_Bags = 24
const script_new_Enemy_Flesh_Feeder = 26
const script_new_EnemyGroup_Flesh_Feeders = 28