Skip to content

Commit

Permalink
forgot 2 files lol
Browse files Browse the repository at this point in the history
  • Loading branch information
panthavma committed Jun 25, 2023
1 parent 364babd commit 65b3361
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 24 deletions.
40 changes: 22 additions & 18 deletions engine/CastagneEngine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func EngineTick(previousMemory, playerInputs):
if(initError):
return

_castProfilingTickStart = OS.get_ticks_usec()
# 1. Frame and input setup
# 0. Memory Set
ResetStateHandles()
Expand Down Expand Up @@ -116,6 +117,10 @@ func EngineTick(previousMemory, playerInputs):
#var inputPhaseFunction = funcref(configData.GetModuleSlot(Castagne.MODULE_SLOTS_BASE.INPUT), "InputPhase")
#ExecuteInternalPhase("Input", activeEIDs, gameStateHandle, inputPhaseFunction)
ExecuteScriptPhase("Freeze", activeEIDs, gameStateHandle)


for m in modules:
m.FrameEnd(gameStateHandle)
return memory

gameStateHandle.GlobalSet("_FrameID", gameStateHandle.GlobalGet("_FrameID")+1)
Expand Down Expand Up @@ -161,6 +166,9 @@ func EngineTick(previousMemory, playerInputs):
ExecuteScriptPhase("Reaction", activeEIDs, gameStateHandle)

# End the frame
for m in modules:
m.FrameEnd(gameStateHandle)

return memory


Expand All @@ -169,30 +177,34 @@ func ExecuteScriptPhase(phaseName, eids, gameStateHandle):
gameStateHandle.SetPhase(phaseName)
for m in modules:
funcref(m, phaseName+"PhaseStart").call_func(gameStateHandle)
var frEntity = funcref(m, phaseName+"PhaseStartEntity")
for eid in eids:
gameStateHandle.PointToEntity(eid)
funcref(m, phaseName+"PhaseStartEntity").call_func(gameStateHandle)
frEntity.call_func(gameStateHandle)
for eid in eids:
gameStateHandle.PointToEntity(eid)
ExecuteCurrentFighterScript(gameStateHandle)
for m in modules:
var frEntity = funcref(m, phaseName+"PhaseEndEntity")
for eid in eids:
gameStateHandle.PointToEntity(eid)
funcref(m, phaseName+"PhaseEndEntity").call_func(gameStateHandle)
frEntity.call_func(gameStateHandle)
funcref(m, phaseName+"PhaseEnd").call_func(gameStateHandle)

func ExecuteInternalPhase(phaseName, activeEIDs, gameStateHandle, phaseFunction):
# :TODO:Panthavma:20220126:Optimize this by making the funcrefs beforehand
for m in modules:
funcref(m, phaseName+"PhaseStart").call_func(gameStateHandle)
var frEntity = funcref(m, phaseName+"PhaseStartEntity")
for eid in activeEIDs:
gameStateHandle.PointToEntity(eid)
funcref(m, phaseName+"PhaseStartEntity").call_func(gameStateHandle)
frEntity.call_func(gameStateHandle)
phaseFunction.call_func(gameStateHandle, activeEIDs)
for m in modules:
var frEntity = funcref(m, phaseName+"PhaseEndEntity")
for eid in activeEIDs:
gameStateHandle.PointToEntity(eid)
funcref(m, phaseName+"PhaseEndEntity").call_func(gameStateHandle)
frEntity.call_func(gameStateHandle)
funcref(m, phaseName+"PhaseEnd").call_func(gameStateHandle)


Expand Down Expand Up @@ -229,25 +241,11 @@ func GetFighterAllScripts(fighterID):
return fighterScripts[fighterID]

func ExecuteFighterScript(fighterScript, gameStateHandle):
#var rEID = moduleCallbackData["RefEID"]
var phaseName = gameStateHandle.GetPhase()
#if(moduleCallbackData["OriginalEID"] == -1):
# moduleCallbackData["OriginalEID"] = eid
# moduleCallbackData["SelectedEID"] = eid
# moduleCallbackData["RefEID"] = eid

var actionList = fighterScript[phaseName]

for action in actionList:
#if(moduleCallbackData["SelectedEID"] != eid):
# eid = moduleCallbackData["SelectedEID"]
# entityState = state[eid]
#if(moduleCallbackData["RefEID"] != rEID):
# rEID = moduleCallbackData["RefEID"]
# moduleCallbackData["rState"] = state[rEID]

action[0].call_func(action[1], gameStateHandle)
#ExecuteAction(action, phaseName, entityState, moduleCallbackData)

func ExecuteAction(action, phaseName, entityState, moduleCallbackData):
# :TODO:Panthavma:20221120:Seems unneeded now
Expand All @@ -257,9 +255,11 @@ func ExecuteAction(action, phaseName, entityState, moduleCallbackData):


func UpdateGraphics(memory):
_castProfilingGraphicsStart = OS.get_ticks_usec()
var gameStateHandle = CreateStateHandle(memory)
for m in modules:
m.UpdateGraphics(gameStateHandle)
_castProfilingGraphicsEnd = OS.get_ticks_usec()



Expand Down Expand Up @@ -463,6 +463,10 @@ func SetInputDevice(pid, deviceName):
# --------------------------------------------------------------------------------------------------
# System

var _castProfilingTickStart = -1
var _castProfilingGraphicsStart = -1
var _castProfilingGraphicsEnd = -1

func _ready():
#useOnline = battleInitData["online"]
useOnline = false
Expand Down
46 changes: 40 additions & 6 deletions engine/CastagneParser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ func _OptimizeActionList(stateName):

var _optimizeActionList_parentWarnings = []
func _OptimizeActionList_Sublist(actionList, baseParentLevel, p, state):
# Call / CallParent
# Empty branch out
var callFuncref = _configData.GetModuleFunctions()["Call"]["ActionFunc"]
var callParentFuncref = _configData.GetModuleFunctions()["CallParent"]["ActionFunc"]

Expand Down Expand Up @@ -322,6 +324,8 @@ func _OptimizeActionList_Sublist(actionList, baseParentLevel, p, state):

var variablesList_OptimPhase2 = {}
func _OptimizeActionListPhase2(stateName):
# Defines replace
# V branch compile time conditions
if(stateName in _optimizedStates):
return
_optimizedStates += [stateName]
Expand All @@ -344,9 +348,10 @@ func _OptimizeActionListPhase2(stateName):

for p in PHASES:
var actionList = state[p]

actionList = _OptimizeActionList_Defines(actionList, state["Variables"], _variables[entity])

actionList = _OptimizeActionList_StaticBranches(actionList)

state[p] = actionList
_states[stateName] = state

Expand Down Expand Up @@ -403,6 +408,29 @@ func _OptimizeActionList_Defines_BranchArgs(branchFuncref, letterArgs, variables
letterArgs = int(letterArgs)
return letterArgs

func _OptimizeActionList_StaticBranches(actionListToParse):
var vbranch = _branchFunctions["V"]
var branchFuncrefs = _branchFunctions.values()
var newActionList = []

for a in actionListToParse:
if(a[0] == vbranch):
var parsedCondition = _Instruction_ParseCondition(a[1][2])
if(parsedCondition[0].is_valid_integer() and parsedCondition[2].is_valid_integer()):
var result = _Instruction_ComputeCondition_Internal(int(parsedCondition[0]), parsedCondition[1], int(parsedCondition[2]))
var chosenBranch = (a[1][0] if result else a[1][1])
newActionList.append_array(_OptimizeActionList_StaticBranches(chosenBranch))
else:
newActionList.push_back(a)
elif a[0] in branchFuncrefs:
a[1][0] = _OptimizeActionList_StaticBranches(a[1][0])
a[1][1] = _OptimizeActionList_StaticBranches(a[1][1])
newActionList.push_back(a)
else:
newActionList.push_back(a)

return newActionList

func _RuntimeStateTagging(stateName):
var state = _states[stateName]
var parentLevel = 0
Expand Down Expand Up @@ -712,7 +740,12 @@ func _ParseForEdition():
var doccontents = line.right(2).strip_edges()
fscs["StateFullDoc"] += doccontents + "\n"
if(doccontents.find("TODO") >= 0):
fscs["StateFlags"] += ["TODO"]
var todoFlags = ["DESIGN", "MOMENTUM", "FRAMEDATA", "ANIM", "VFX", "SOUND", "BUG"]
var todoFlag = "TODO"
for tf in todoFlags:
if(doccontents.find("TODO"+tf) >= 0):
todoFlag = "TODO"+tf
fscs["StateFlags"] += [todoFlag]
if(doccontents.find("CASTDO") >= 0):
fscs["StateFlags"] += ["CASTTODO"]
elif(line.begins_with("#")):
Expand Down Expand Up @@ -1205,7 +1238,7 @@ func _GetEntityNameFromStateName(stateName):
return entity

onready var KnownVariableTypes = {"int":Castagne.VARIABLE_TYPE.Int, "str":Castagne.VARIABLE_TYPE.Str, "bool":Castagne.VARIABLE_TYPE.Bool}
func _ExtractVariable(line):
func _ExtractVariable(line, returnIncompleteType = false):
# Structure: var NAME int() = 5
var variableMutability = null
var variableValue = null
Expand Down Expand Up @@ -1433,10 +1466,11 @@ func _Instruction_ComputeCondition(letterArgs, stateHandle):
return false

var firstPart = ArgInt([parsedCondition[0]], stateHandle, 0, 0)
var condition = parsedCondition[1]
var secondPart = ArgInt([parsedCondition[2]], stateHandle, 0, 0)
var diff = firstPart - secondPart
return _Instruction_ComputeCondition_Internal(firstPart, parsedCondition[1], secondPart)

func _Instruction_ComputeCondition_Internal(firstPart, condition, secondPart):
var diff = firstPart - secondPart
if(diff == 0):
return (abs(condition) <= 1)
return (sign(condition) == sign(diff))

0 comments on commit 65b3361

Please sign in to comment.