- Joined
- Aug 6, 2009
- Messages
- 697
Is it possible to skip the actions of EVENT_PLAYER_MOUSE_MOVE? I've tried disabling the trigger before BlzSetMousePos is called and enabling it after. However, the actions still fire. I tried removing it from trigger queue before and/or after it is called as well. I've tried making it skip it with a real timer and a boolean and it still did not work. I have posted the code below. Alloc is just implemented by the Problem Child Code.
JASS:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ Alloc ~~ By Sevion ~~ Version 1.09 ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// What is Alloc?
// - Alloc implements an intuitive allocation method for array structs
//
// =Pros=
// - Efficient.
// - Simple.
// - Less overhead than regular structs.
//
// =Cons=
// - Must use array structs (hardly a con).
// - Must manually call OnDestroy.
// - Must use Delegates for inheritance.
// - No default values for variables (use onInit instead).
// - No array members (use another Alloc struct as a linked list or type declaration).
//
// Methods:
// - struct.allocate()
// - struct.deallocate()
//
// These methods are used just as they should be used in regular structs.
//
// Modules:
// - Alloc
// Implements the most basic form of Alloc. Includes only create and destroy
// methods.
//
// Details:
// - Less overhead than regular structs
//
// - Use array structs when using Alloc. Put the implement at the top of the struct.
//
// - Alloc operates almost exactly the same as default structs in debug mode with the exception of onDestroy.
//
// How to import:
// - Create a trigger named Alloc.
// - Convert it to custom text and replace the whole trigger text with this.
//
// Thanks:
// - Nestharus for the method of allocation and suggestions on further merging.
// - Bribe for suggestions like the static if and method names.
// - PurgeandFire111 for some suggestions like the merging of Alloc and AllocX as well as OnDestroy stuff.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library Alloc
module Alloc
private static integer instanceCount = 0
private thistype recycle
static method allocate takes nothing returns thistype
local thistype this
if (thistype(0).recycle == 0) then
debug if (instanceCount == JASS_MAX_ARRAY_SIZE - 1) then
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Alloc ERROR: Attempted to allocate too many instances!")
debug return 0
debug endif
set instanceCount = instanceCount + 1
set this = instanceCount
else
set this = thistype(0).recycle
set thistype(0).recycle = thistype(0).recycle.recycle
endif
debug set this.recycle = -1
return this
endmethod
method deallocate takes nothing returns nothing
debug if (this.recycle != -1) then
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Alloc ERROR: Attempted to deallocate an invalid instance at [" + I2S(this) + "]!")
debug return
debug endif
set this.recycle = thistype(0).recycle
set thistype(0).recycle = this
endmethod
endmodule
endlibrary
JASS:
library cameraSystem initializer Init_cameraSystem
//requires alloc
//setup begin
//I am making this in a struct despite it only being used on 12 players.
globals
private integer MAX_PLAYERS = 12
private integer debug_mode = 1
private real DEFAULT_PANNING_TIME = 0.1
private real array mouseX
private real array mouseY
private real array prevMouseX
private real array prevMouseY
private real array skipTimer
private trigger mouseMove = CreateTrigger()
endglobals
//setup end
globals
cameraSys array cs_Index
integer cs_Max = -1
private integer cs_Current = 0
private constant real REPEATED_TIME = 0.03125
endglobals
function mouseActions takes nothing returns nothing //<=======ACTIONS ON MOUSE MOVE HERE
local integer i
set i = GetPlayerId(GetTriggerPlayer())
//if skipTimer[i] < REPEATED_TIME then
if GetTriggerPlayer() == GetLocalPlayer() then
set mouseX[i] = BlzGetTriggerPlayerMouseX()
set mouseY[i] = BlzGetTriggerPlayerMouseY()
endif
//else
//set skipTimer[i] = skipTimer[i] - REPEATED_TIME
//endif
endfunction
struct cameraSys extends array
implement Alloc
private integer myPlayer
private unit u
private real maxDistance
private real currentDistance
private real angle
private real myX
private real myY
private real panningTime //Default should be 0.10 or 0.05
public integer active
static method create takes unit u, integer myPlayer, real maxDistance returns thistype
local thistype this = thistype.allocate()
set this.myPlayer = myPlayer
set this.active = 1
set this.u = u
set this.maxDistance = maxDistance
set this.panningTime = DEFAULT_PANNING_TIME
set cs_Max = cs_Max + 1
set cs_Index[cs_Max] = this
return this
endmethod
method destroy takes nothing returns nothing
set this.active = 0
call this.deallocate()
endmethod
method getDist takes real x1, real y1, real x2, real y2 returns real
local real x
local real y
local real dist
set x = x2 - x1
set x = x * x
set y = y2 - y1
set y = y * y
set dist = SquareRoot(x + y)
return dist
endmethod
method update takes real delta returns nothing
local real x
local real y
local real angle
local real distance
//call DisableTrigger( mouseMove )
if GetUnitState(this.u, UNIT_STATE_LIFE) < 0.405 then
call this.destroy()
else
set x = GetWidgetX(this.u)
set y = GetWidgetY(this.u)
set angle = Atan2(mouseY[this.myPlayer] - y, mouseX[this.myPlayer] - x)
set distance = getDist(x, y, mouseX[this.myPlayer], mouseY[this.myPlayer])
if prevMouseX[this.myPlayer] != mouseX[this.myPlayer] and prevMouseY[this.myPlayer] != mouseY[this.myPlayer] then
set this.currentDistance = distance
set this.angle = angle
if this.myTimer <= 0 then
set this.myTimer = 0.15
if Player(this.myPlayer) == GetLocalPlayer() then
//set skipTimer[this.myPlayer] = REPEATED_TIME * 100
//call QueuedTriggerRemoveBJ(mouseMove)
call BlzSetMousePos(BlzGetLocalClientWidth() / 2, BlzGetLocalClientHeight() / 2) //<==========PROBLEM CHILD IS HERE
//call BlzSetMousePos(BlzGetLocalClientWidth() / 2, BlzGetLocalClientHeight() / 2)
//call QueuedTriggerRemoveBJ(mouseMove)
endif
else
set this.myTimer = this.myTimer - 0.03
endif
//call QueuedTriggerRemoveBJ(mouseMove)
endif
if this.currentDistance >= this.maxDistance then
set this.myX = x + (this.maxDistance * Cos(this.angle))
set this.myY = y + (this.maxDistance * Sin(this.angle))
else
set this.myX = mouseX[this.myPlayer]
set this.myY = mouseY[this.myPlayer]
set this.myX = x + (this.currentDistance * Cos(this.angle))
set this.myY = y + (this.currentDistance * Sin(this.angle))
endif
set prevMouseX[this.myPlayer] = mouseX[this.myPlayer]
set prevMouseY[this.myPlayer] = mouseY[this.myPlayer]
if debug_mode == 1 then
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " X: " + R2S(this.myX) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " Y: " + R2S(this.myY) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " ANGLE: " + R2S(angle) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " CURRENT ANGLE: " + R2S(this.angle) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " DISTANCE: " + R2S(distance) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " CURRENT DISTANCE: " + R2S(this.currentDistance) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " PANNING TIME: " + R2S(this.panningTime) )
if Player(this.myPlayer) == GetLocalPlayer() then
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " Screen Height: " + I2S(BlzGetLocalClientHeight()) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " Screen Width: " + I2S(BlzGetLocalClientWidth()) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " Screen Height / 2: " + I2S(BlzGetLocalClientHeight() / 2) )
call DisplayTextToForce( GetPlayersAll(), I2S(this.myPlayer) + " Screen Width / 2: " + I2S(BlzGetLocalClientWidth() / 2) )
endif
endif
if Player(this.myPlayer) == GetLocalPlayer() then
call PanCameraToTimed (this.myX, this.myY, this.panningTime)
endif
endif
//call EnableTrigger( mouseMove )
endmethod
method setPanningTime takes real time returns nothing
set this.panningTime = time
endmethod
method setMaxDistance takes real distance returns nothing
set this.maxDistance = distance
endmethod
endstruct
//indexer
private function Actions takes nothing returns nothing
if cs_Max > -1 then
set cs_Current = 0
loop
if cs_Index[cs_Current].active == 0 then
set cs_Index[cs_Current] = cs_Index[cs_Max]
set cs_Max = cs_Max - 1
set cs_Current = cs_Current - 1
else
call cs_Index[cs_Current].update(REPEATED_TIME)
endif
set cs_Current = cs_Current + 1
exitwhen cs_Current > cs_Max
endloop
endif
endfunction
private function Init_cameraSystem takes nothing returns nothing
local integer i
local trigger CSIndex = CreateTrigger()
call TriggerRegisterTimerEvent(CSIndex, REPEATED_TIME, true)
call TriggerAddAction(CSIndex, function Actions)
set i = 0
loop
exitwhen i >= MAX_PLAYERS
call TriggerRegisterPlayerEvent(mouseMove, Player(i), EVENT_PLAYER_MOUSE_MOVE)
set i = i + 1
endloop
call TriggerAddAction(mouseMove, function mouseActions)
endfunction
endlibrary