commit
5838436e31
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<title>Icons / Toolbar / Non Uniform Scaling</title>
|
||||||
|
<defs>
|
||||||
|
<rect id="path-1" x="3" y="3" width="18" height="18"></rect>
|
||||||
|
<mask id="mask-2" maskContentUnits="userSpaceOnUse" maskUnits="objectBoundingBox" x="0" y="0" width="18" height="18" fill="white">
|
||||||
|
<use xlink:href="#path-1"></use>
|
||||||
|
</mask>
|
||||||
|
</defs>
|
||||||
|
<g id="Icons-/-Toolbar-/-Non-Uniform-Scaling" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||||
|
<g id="Group">
|
||||||
|
<rect id="Icon-Background" x="0" y="0" width="24" height="24"></rect>
|
||||||
|
<g id="Group-3" transform="translate(4.644661, 5.000000)" fill="#65C98C">
|
||||||
|
<rect id="Rectangle" x="3.16582489" y="1.21320344" width="1.95262146" height="5"></rect>
|
||||||
|
<polygon id="Rectangle" points="4.14213562 -1.71418435e-13 8.28427125 4.14213562 -1.11910481e-13 4.14213562"></polygon>
|
||||||
|
</g>
|
||||||
|
<g id="Group-4" transform="translate(13.073593, 10.857864)" fill="#65C98C">
|
||||||
|
<g id="Group-2" transform="translate(0.000000, 0.000000)">
|
||||||
|
<rect id="Rectangle" x="0" y="3.16582489" width="4" height="1.95262146"></rect>
|
||||||
|
<polygon id="Rectangle" points="5.71320344 4.14213562 1.57106781 8.28427125 1.57106781 1.14575016e-13"></polygon>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
<rect id="Rectangle" stroke="#65C98C" fill="#65C98C" x="3.5" y="12.5" width="8" height="8"></rect>
|
||||||
|
<use id="Rectangle" stroke="#65C98C" mask="url(#mask-2)" stroke-width="2" stroke-dasharray="1" xlink:href="#path-1"></use>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.8 KiB |
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"Amazon": {
|
|
||||||
"AssetProcessor": {
|
|
||||||
"Settings": {
|
|
||||||
"RC cgf": {
|
|
||||||
"ignore": true
|
|
||||||
},
|
|
||||||
"RC fbx": {
|
|
||||||
"ignore": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,129 @@
|
|||||||
|
"""
|
||||||
|
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
its licensors.
|
||||||
|
|
||||||
|
For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
|
||||||
|
Test case ID: T92562988
|
||||||
|
Test Case Title: Left-click/double click expands and collapses node categories
|
||||||
|
URL of the test case: https://testrail.agscollab.com/index.php?/tests/view/92562988
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# fmt: off
|
||||||
|
class Tests():
|
||||||
|
pane_open = ("Script Canvas pane successfully opened", "Script Canvas pane failed to open")
|
||||||
|
click_expand = ("Category expanded on left click", "Category failed to expand on left click")
|
||||||
|
click_collapse = ("Category collapsed on left click", "Category failed to collapse on left click")
|
||||||
|
dClick_expand = ("Category expanded on double click", "Category failed to expand on double click")
|
||||||
|
dClick_collapse = ("Category collapsed on double click", "Category failed to collapse on double click")
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
|
def NodeCategory_ExpandOnClick():
|
||||||
|
"""
|
||||||
|
Summary:
|
||||||
|
Verifying the expand/collapse functionality on node categories
|
||||||
|
|
||||||
|
Expected Behavior:
|
||||||
|
The node category should expand when double clicked or when the drop down indicator is
|
||||||
|
left-clicked. Once expanded, it should be collapsed via the same actions.
|
||||||
|
|
||||||
|
Test Steps:
|
||||||
|
1) Open Script Canvas pane
|
||||||
|
2) Get the SC window objects
|
||||||
|
3) Ensure all categories are collapsed for a clean state
|
||||||
|
4) Left-Click on a node category arrow to expand it
|
||||||
|
5) Verify it expanded
|
||||||
|
6) Left-Click on a node category arrow to collapse it
|
||||||
|
7) Verify it collapsed
|
||||||
|
8) Double-Click on a node category to expand it
|
||||||
|
9) Verify it expanded
|
||||||
|
10) Double-Click on a node category to collapse it
|
||||||
|
11) Verify it collapsed
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- This test file must be called from the Open 3D Engine Editor command terminal
|
||||||
|
- Any passed and failed tests are written to the Editor.log file.
|
||||||
|
Parsing the file or running a log_monitor are required to observe the test results.
|
||||||
|
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
from utils import Report
|
||||||
|
from PySide2 import QtCore, QtWidgets, QtTest
|
||||||
|
from PySide2.QtTest import QTest
|
||||||
|
import pyside_utils
|
||||||
|
import azlmbr.legacy.general as general
|
||||||
|
|
||||||
|
def left_click_arrow(item_view, index):
|
||||||
|
original_state = item_view.isExpanded(index)
|
||||||
|
rect_center_y = item_view.visualRect(index).center().y()
|
||||||
|
rect_left_x = item_view.visualRect(index).left()
|
||||||
|
for i in range(5): # this range can be increased for safe side
|
||||||
|
QtTest.QTest.mouseClick(
|
||||||
|
item_view.viewport(),
|
||||||
|
QtCore.Qt.LeftButton,
|
||||||
|
QtCore.Qt.NoModifier,
|
||||||
|
QtCore.QPoint(rect_left_x - i, rect_center_y),
|
||||||
|
)
|
||||||
|
if item_view.isExpanded(index) != original_state:
|
||||||
|
break
|
||||||
|
|
||||||
|
def double_click(item_view, index):
|
||||||
|
item_index_center = item_view.visualRect(index).center()
|
||||||
|
# Left click on the item before trying to double click, will otherwise fail to expand
|
||||||
|
# as first click would highlight and second click would be a 'single click'
|
||||||
|
pyside_utils.item_view_index_mouse_click(item_view, index)
|
||||||
|
QTest.mouseDClick(item_view.viewport(), QtCore.Qt.LeftButton, QtCore.Qt.NoModifier, item_index_center)
|
||||||
|
|
||||||
|
# 1) Open Script Canvas pane
|
||||||
|
general.open_pane("Script Canvas")
|
||||||
|
Report.critical_result(Tests.pane_open, general.is_pane_visible("Script Canvas"))
|
||||||
|
|
||||||
|
# 2) Get the SC window objects
|
||||||
|
editor_window = pyside_utils.get_editor_main_window()
|
||||||
|
sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
|
||||||
|
if sc.findChild(QtWidgets.QDockWidget, "NodePalette") is None:
|
||||||
|
action = pyside_utils.find_child_by_pattern(sc, {"text": "Node Palette", "type": QtWidgets.QAction})
|
||||||
|
action.trigger()
|
||||||
|
node_palette = sc.findChild(QtWidgets.QDockWidget, "NodePalette")
|
||||||
|
nodeTree = node_palette.findChild(QtWidgets.QTreeView, "treeView")
|
||||||
|
ai_index = pyside_utils.find_child_by_pattern(nodeTree, "AI")
|
||||||
|
|
||||||
|
# 3) Ensure all categories are collapsed for a clean state
|
||||||
|
nodeTree.collapseAll()
|
||||||
|
|
||||||
|
# 4) Left-Click on a node category arrow to expand it
|
||||||
|
left_click_arrow(nodeTree, ai_index)
|
||||||
|
|
||||||
|
# 5) Verify it expanded
|
||||||
|
Report.result(Tests.click_expand, nodeTree.isExpanded(ai_index))
|
||||||
|
|
||||||
|
# 6) Left-Click on a node category arrow to collapse it
|
||||||
|
left_click_arrow(nodeTree, ai_index)
|
||||||
|
|
||||||
|
# 7) Verify it collapsed
|
||||||
|
Report.result(Tests.click_collapse, not nodeTree.isExpanded(ai_index))
|
||||||
|
|
||||||
|
# 8) Double-Click on a node category to expand it
|
||||||
|
double_click(nodeTree, ai_index)
|
||||||
|
|
||||||
|
# 9) Verify it expanded
|
||||||
|
Report.result(Tests.dClick_expand, nodeTree.isExpanded(ai_index))
|
||||||
|
|
||||||
|
# 10) Double-Click on a node category to collapse it
|
||||||
|
double_click(nodeTree, ai_index)
|
||||||
|
|
||||||
|
# 11) Verify it collapsed
|
||||||
|
Report.result(Tests.dClick_collapse, not nodeTree.isExpanded(ai_index))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import ImportPathHelper as imports
|
||||||
|
imports.init()
|
||||||
|
from utils import Report
|
||||||
|
Report.start_test(NodeCategory_ExpandOnClick)
|
||||||
@ -0,0 +1,112 @@
|
|||||||
|
"""
|
||||||
|
All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
its licensors.
|
||||||
|
|
||||||
|
For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
|
||||||
|
Test Case Title: Event can return a value of set type successfully
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# fmt: off
|
||||||
|
class Tests():
|
||||||
|
level_created = ("Successfully created temporary level", "Failed to create temporary level")
|
||||||
|
entity_created = ("Successfully created test entity", "Failed to create test entity")
|
||||||
|
enter_game_mode = ("Successfully entered game mode", "Failed to enter game mode")
|
||||||
|
lines_found = ("Successfully found expected message", "Failed to find expected message")
|
||||||
|
exit_game_mode = ("Successfully exited game mode", "Failed to exit game mode")
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
|
def ScriptEvents_ReturnSetType_Successfully():
|
||||||
|
"""
|
||||||
|
Summary: A temporary level is created with an Entity having ScriptCanvas component.
|
||||||
|
ScriptEvent(T92569006_ScriptEvent.scriptevents) is created with one Method that has a return value.
|
||||||
|
ScriptCanvas(T92569006_ScriptCanvas.scriptcanvas) is attached to Entity. Graph has Send node that sends the Method
|
||||||
|
of the ScriptEvent and prints the returned result ( On Entity Activated -> Send node -> Print) and Receive node is
|
||||||
|
set to return custom value ( Receive node -> Print).
|
||||||
|
Verify that the entity containing T92569006_ScriptCanvas.scriptcanvas should print the custom value set in both
|
||||||
|
Send and Receive nodes.
|
||||||
|
|
||||||
|
Expected Behavior:
|
||||||
|
After entering game mode, the graph on the entity should print an expected message to the console
|
||||||
|
|
||||||
|
Test Steps:
|
||||||
|
1) Create test level
|
||||||
|
2) Create test entity
|
||||||
|
3) Start Tracer
|
||||||
|
4) Enter Game Mode
|
||||||
|
5) Read for line
|
||||||
|
6) Exit Game Mode
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- This test file must be called from the Open 3D Engine Editor command terminal
|
||||||
|
- Any passed and failed tests are written to the Editor.log file.
|
||||||
|
Parsing the file or running a log_monitor are required to observe the test results.
|
||||||
|
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
from editor_entity_utils import EditorEntity as Entity
|
||||||
|
from utils import Report
|
||||||
|
from utils import TestHelper as helper
|
||||||
|
from utils import Tracer
|
||||||
|
|
||||||
|
import azlmbr.legacy.general as general
|
||||||
|
import azlmbr.asset as asset
|
||||||
|
import azlmbr.math as math
|
||||||
|
import azlmbr.bus as bus
|
||||||
|
|
||||||
|
LEVEL_NAME = "tmp_level"
|
||||||
|
WAIT_TIME = 3.0 # SECONDS
|
||||||
|
EXPECTED_LINES = ["T92569006_ScriptEvent_Sent", "T92569006_ScriptEvent_Received"]
|
||||||
|
SC_ASSET_PATH = os.path.join("ScriptCanvas", "T92569006_ScriptCanvas.scriptcanvas")
|
||||||
|
|
||||||
|
def create_editor_entity(name, sc_asset):
|
||||||
|
entity = Entity.create_editor_entity(name)
|
||||||
|
sc_comp = entity.add_component("Script Canvas")
|
||||||
|
asset_id = asset.AssetCatalogRequestBus(bus.Broadcast, "GetAssetIdByPath", sc_asset, math.Uuid(), False)
|
||||||
|
sc_comp.set_component_property_value("Script Canvas Asset|Script Canvas Asset", asset_id)
|
||||||
|
Report.critical_result(Tests.entity_created, entity.id.isValid())
|
||||||
|
|
||||||
|
def locate_expected_lines(line_list: list):
|
||||||
|
found_lines = [printInfo.message.strip() for printInfo in section_tracer.prints]
|
||||||
|
|
||||||
|
return all(line in found_lines for line in line_list)
|
||||||
|
|
||||||
|
# 1) Create temp level
|
||||||
|
general.idle_enable(True)
|
||||||
|
result = general.create_level_no_prompt(LEVEL_NAME, 128, 1, 512, True)
|
||||||
|
Report.critical_result(Tests.level_created, result == 0)
|
||||||
|
helper.wait_for_condition(lambda: general.get_current_level_name() == LEVEL_NAME, WAIT_TIME)
|
||||||
|
general.close_pane("Error Report")
|
||||||
|
|
||||||
|
# 2) Create test entity
|
||||||
|
create_editor_entity("TestEntity", SC_ASSET_PATH)
|
||||||
|
|
||||||
|
# 3) Start Tracer
|
||||||
|
with Tracer() as section_tracer:
|
||||||
|
|
||||||
|
# 4) Enter Game Mode
|
||||||
|
helper.enter_game_mode(Tests.enter_game_mode)
|
||||||
|
|
||||||
|
# 5) Read for line
|
||||||
|
lines_located = helper.wait_for_condition(lambda: locate_expected_lines(EXPECTED_LINES), WAIT_TIME)
|
||||||
|
Report.result(Tests.lines_found, lines_located)
|
||||||
|
|
||||||
|
# 6) Exit Game Mode
|
||||||
|
helper.exit_game_mode(Tests.exit_game_mode)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import ImportPathHelper as imports
|
||||||
|
|
||||||
|
imports.init()
|
||||||
|
|
||||||
|
from utils import Report
|
||||||
|
|
||||||
|
Report.start_test(ScriptEvents_ReturnSetType_Successfully)
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,126 @@
|
|||||||
|
<ObjectStream version="3">
|
||||||
|
<Class name="ScriptEventsAsset" version="1" type="{CB4D603E-8CB0-4D80-8165-4244F28AF187}">
|
||||||
|
<Class name="ScriptEvent" field="m_definition" version="1" type="{10A08CD3-32C9-4E18-8039-4B8A8157918E}">
|
||||||
|
<Class name="unsigned int" field="m_version" value="4" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="VersionedProperty" field="m_name" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{1E4A668C-8300-4047-AEA2-F5FEBF11EBA0}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Name" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="1" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}">
|
||||||
|
<Class name="VersionedProperty" field="element" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{1E4A668C-8300-4047-AEA2-F5FEBF11EBA0}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Name" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="EventName" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="T92569006_ScriptEvent" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="VersionedProperty" field="m_category" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{73D97530-40F2-48FD-91BA-C20ABB0C6620}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Category" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="Script Events" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="VersionedProperty" field="m_tooltip" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{9D4BB4C1-8A94-43B9-BED7-C104D7758916}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Tooltip" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="VersionedProperty" field="m_addressType" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{8D528B1F-1FEE-43BA-BD5D-C7EB3707B781}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Address Type" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZ::Uuid" field="m_data" value="{C0F1AFAD-5CB3-450E-B0F5-ADB5D46B0E22}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="AZStd::vector" field="m_methods" type="{D9866B79-D11A-58E6-B974-0B45783F53A4}">
|
||||||
|
<Class name="Method" field="element" type="{E034EA83-C798-413D-ACE8-4923C51CF4F7}">
|
||||||
|
<Class name="VersionedProperty" field="m_name" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{0DEB2C25-6B32-44B7-9750-56CAA789C016}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Name" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="MethodName" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="VersionedProperty" field="m_tooltip" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{664A28E6-AD74-4EA7-BDE8-49CA02D1C5C7}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Tooltip" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="VersionedProperty" field="m_returnType" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{D2C6D979-A036-4523-B79E-98D3A1D4F623}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="String" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="1" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}">
|
||||||
|
<Class name="VersionedProperty" field="element" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{A2629A45-21A2-4101-BF0D-1F843B3398D7}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Return Type" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZ::Uuid" field="m_data" value="{C0F1AFAD-5CB3-450E-B0F5-ADB5D46B0E22}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZ::Uuid" field="m_data" value="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="AZStd::vector" field="m_parameters" type="{6ED13EA7-791B-57A8-A4F1-560B5F35B472}">
|
||||||
|
<Class name="Parameter" field="element" type="{0DA4809B-08A6-49DC-9024-F81645D97FAC}">
|
||||||
|
<Class name="VersionedProperty" field="m_name" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{CD536CCB-29E7-4155-8C20-E37FA3B3A3D2}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Name" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="ParameterName" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="VersionedProperty" field="m_tooltip" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{62907B85-6C12-49E3-8A92-82E41AF029D5}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="Tooltip" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZStd::string" field="m_data" value="" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
<Class name="VersionedProperty" field="m_type" version="4" type="{828CA9C0-32F1-40B3-8018-EE7C3C38192A}">
|
||||||
|
<Class name="AZ::Uuid" field="m_id" value="{E3509DD4-13B0-4096-8AC4-115D9A8BCD6B}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
<Class name="AZStd::string" field="m_label" value="String" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
|
||||||
|
<Class name="unsigned int" field="m_version" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
|
||||||
|
<Class name="AZStd::vector" field="m_versions" type="{326CAAFE-9101-56E2-B869-D770629A6B19}"/>
|
||||||
|
<Class name="any" field="m_data" type="{03924488-C7F4-4D6D-948B-ABC2D1AE2FD3}">
|
||||||
|
<Class name="AZ::Uuid" field="m_data" value="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</Class>
|
||||||
|
</ObjectStream>
|
||||||
|
|
||||||
@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef __CREBASECLOUD_H__
|
|
||||||
#define __CREBASECLOUD_H__
|
|
||||||
|
|
||||||
//================================================================================
|
|
||||||
|
|
||||||
class SCloudParticle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
inline SCloudParticle();
|
|
||||||
inline SCloudParticle(const Vec3& vPos, float fRadius, const ColorF& baseColor, float fTransparency = 0);
|
|
||||||
inline SCloudParticle(const Vec3& vPos, float fRadiusX, float fRadiusY, float fRotMin, float fRotMax, Vec2 vUV[]);
|
|
||||||
inline ~SCloudParticle();
|
|
||||||
|
|
||||||
float GetRadiusX() const { return m_fSize[0]; }
|
|
||||||
float GetRadiusY() const { return m_fSize[1]; }
|
|
||||||
float GetTransparency() const { return m_fTransparency; }
|
|
||||||
const Vec3& GetPosition() const { return m_vPosition; }
|
|
||||||
const ColorF& GetBaseColor() const { return m_vBaseColor; }
|
|
||||||
uint32 GetNumLitColors() const { return m_vLitColors.size(); }
|
|
||||||
inline const ColorF GetLitColor(unsigned int index) const;
|
|
||||||
float GetSquareSortDistance() const { return m_fSquareSortDistance; }
|
|
||||||
|
|
||||||
//! Sets the radius of the particle.
|
|
||||||
void SetRadiusX(float rad) { m_fSize[0] = rad; }
|
|
||||||
void SetRadiusY(float rad) { m_fSize[1] = rad; }
|
|
||||||
void SetTransparency(float trans) { m_fTransparency = trans; }
|
|
||||||
void SetPosition(const Vec3& pos) { m_vPosition = pos; }
|
|
||||||
void SetBaseColor(const ColorF& col) { m_vBaseColor = col; }
|
|
||||||
void AddLitColor(const ColorF& col) { m_vLitColors.push_back(col); }
|
|
||||||
void ClearLitColors() { m_vLitColors.clear(); }
|
|
||||||
void SetSquareSortDistance(float fSquareDistance) { m_fSquareSortDistance = fSquareDistance; }
|
|
||||||
|
|
||||||
bool operator<(const SCloudParticle& p) const
|
|
||||||
{
|
|
||||||
return (m_fSquareSortDistance < p.m_fSquareSortDistance);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator>(const SCloudParticle& p) const
|
|
||||||
{
|
|
||||||
return (m_fSquareSortDistance > p.m_fSquareSortDistance);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
float m_fTransparency;
|
|
||||||
Vec3 m_vPosition;
|
|
||||||
float m_fSize[2];
|
|
||||||
float m_fRotMin;
|
|
||||||
float m_fRotMax;
|
|
||||||
ColorF m_vBaseColor;
|
|
||||||
TArray<ColorF> m_vLitColors;
|
|
||||||
Vec3 m_vEye;
|
|
||||||
|
|
||||||
// for sorting particles during shading
|
|
||||||
float m_fSquareSortDistance;
|
|
||||||
public:
|
|
||||||
Vec2 m_vUV[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
inline SCloudParticle::SCloudParticle()
|
|
||||||
{
|
|
||||||
m_fSize[0] = 0;
|
|
||||||
m_fTransparency = 0;
|
|
||||||
m_vPosition = Vec3(0, 0, 0);
|
|
||||||
m_vBaseColor = Col_Black;
|
|
||||||
m_vEye = Vec3(0, 0, 0);
|
|
||||||
m_fSquareSortDistance = 0;
|
|
||||||
|
|
||||||
m_vLitColors.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SCloudParticle::SCloudParticle(const Vec3& pos, float fRadius, const ColorF& baseColor, float fTransparency)
|
|
||||||
{
|
|
||||||
m_fSize[0] = fRadius;
|
|
||||||
m_fSize[1] = fRadius;
|
|
||||||
m_fTransparency = fTransparency;
|
|
||||||
m_vPosition = pos;
|
|
||||||
m_vBaseColor = baseColor;
|
|
||||||
m_vUV[0] = Vec2(0, 0);
|
|
||||||
m_vUV[1] = Vec2(1, 1);
|
|
||||||
|
|
||||||
m_fRotMin = 0;
|
|
||||||
m_fRotMax = 0;
|
|
||||||
m_vEye = Vec3(0, 0, 0);
|
|
||||||
m_fSquareSortDistance = 0;
|
|
||||||
|
|
||||||
m_vLitColors.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SCloudParticle::SCloudParticle(const Vec3& vPos, float fRadiusX, float fRadiusY, float fRotMin, float fRotMax, Vec2 vUV[2])
|
|
||||||
{
|
|
||||||
m_fSize[0] = fRadiusX;
|
|
||||||
m_fSize[1] = fRadiusY;
|
|
||||||
m_vPosition = vPos;
|
|
||||||
m_vBaseColor = Col_White;
|
|
||||||
m_vUV[0] = vUV[0];
|
|
||||||
m_vUV[1] = vUV[1];
|
|
||||||
m_fRotMin = fRotMin;
|
|
||||||
m_fRotMax = fRotMax;
|
|
||||||
|
|
||||||
m_fTransparency = 1.0f;
|
|
||||||
m_vEye = Vec3(0, 0, 0);
|
|
||||||
m_fSquareSortDistance = 0;
|
|
||||||
|
|
||||||
m_vLitColors.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline SCloudParticle::~SCloudParticle()
|
|
||||||
{
|
|
||||||
m_vLitColors.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const ColorF SCloudParticle::GetLitColor(unsigned int index) const
|
|
||||||
{
|
|
||||||
if (index <= m_vLitColors.size())
|
|
||||||
{
|
|
||||||
return m_vLitColors[index];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Col_Black;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
class CREBaseCloud
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
friend class CRECloud;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CREBaseCloud()
|
|
||||||
: CRendElementBase()
|
|
||||||
{
|
|
||||||
mfSetType(eDATA_Cloud);
|
|
||||||
mfUpdateFlags(FCEF_TRANSFORM);
|
|
||||||
}
|
|
||||||
virtual void SetParticles(SCloudParticle* pParticles, int nNumParticles) = 0;
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __CREBASECLOUD_H__
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
#ifndef _CREFOGVOLUME_
|
|
||||||
#define _CREFOGVOLUME_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "VertexFormats.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct IFogVolumeRenderNode;
|
|
||||||
|
|
||||||
|
|
||||||
class CREFogVolume
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CREFogVolume();
|
|
||||||
|
|
||||||
virtual ~CREFogVolume();
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 m_center;
|
|
||||||
uint32 m_viewerInsideVolume : 1;
|
|
||||||
uint32 m_affectsThisAreaOnly : 1;
|
|
||||||
uint32 m_stencilRef : 8;
|
|
||||||
uint32 m_volumeType : 1;
|
|
||||||
uint32 m_reserved : 21;
|
|
||||||
AABB m_localAABB;
|
|
||||||
Matrix34 m_matWSInv;
|
|
||||||
float m_globalDensity;
|
|
||||||
float m_densityOffset;
|
|
||||||
float m_nearCutoff;
|
|
||||||
Vec2 m_softEdgesLerp;
|
|
||||||
ColorF m_fogColor; // color already combined with fHDRDynamic
|
|
||||||
Vec3 m_heightFallOffDirScaled;
|
|
||||||
Vec3 m_heightFallOffBasePoint;
|
|
||||||
Vec3 m_eyePosInWS;
|
|
||||||
Vec3 m_eyePosInOS;
|
|
||||||
Vec3 m_rampParams;
|
|
||||||
Vec3 m_windOffset;
|
|
||||||
float m_noiseScale;
|
|
||||||
Vec3 m_noiseFreq;
|
|
||||||
float m_noiseOffset;
|
|
||||||
float m_noiseElapsedTime;
|
|
||||||
Vec3 m_scale;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef _CREFOGVOLUME_
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
#ifndef _CREGameEffect_
|
|
||||||
#define _CREGameEffect_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
// Name: IREGameEffect
|
|
||||||
// Desc: Interface for game effect render elements, designed to be instantiated in game code, and
|
|
||||||
// called from the CREGameEffect within the engine. This then allows render elements
|
|
||||||
// to be created in game code as well as in the engine.
|
|
||||||
// Author: James Chilvers
|
|
||||||
//==================================================================================================
|
|
||||||
struct IREGameEffect
|
|
||||||
{
|
|
||||||
virtual ~IREGameEffect(){}
|
|
||||||
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow) = 0;
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm, CRenderObject* renderObj) = 0;
|
|
||||||
};//------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
// Name: CREGameEffect
|
|
||||||
// Desc: Render element that uses the IREGameEffect interface for its functionality
|
|
||||||
// Author: James Chilvers
|
|
||||||
//==================================================================================================
|
|
||||||
class CREGameEffect
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CREGameEffect();
|
|
||||||
~CREGameEffect();
|
|
||||||
|
|
||||||
// CRendElementBase interface
|
|
||||||
void mfPrepare(bool bCheckOverflow);
|
|
||||||
bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
// CREGameEffect interface
|
|
||||||
inline void SetPrivateImplementation(IREGameEffect* pImpl) { m_pImpl = pImpl; }
|
|
||||||
inline IREGameEffect* GetPrivateImplementation() const { return m_pImpl; }
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
|
|
||||||
IREGameEffect* m_pImpl; // Implementation of of render element
|
|
||||||
};//------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // #ifndef _CREGameEffect_
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Backend part of geometry cache rendering
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#if defined(USE_GEOM_CACHES)
|
|
||||||
|
|
||||||
#include <Vertex.h>
|
|
||||||
#include <CryCommon/StaticInstance.h>
|
|
||||||
|
|
||||||
class CREGeomCache
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct SMeshInstance
|
|
||||||
{
|
|
||||||
AABB m_aabb;
|
|
||||||
Matrix34 m_matrix;
|
|
||||||
Matrix34 m_prevMatrix;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SMeshRenderData
|
|
||||||
{
|
|
||||||
DynArray<SMeshInstance> m_instances;
|
|
||||||
_smart_ptr<IRenderMesh> m_pRenderMesh;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct UpdateList
|
|
||||||
{
|
|
||||||
CryCriticalSection m_mutex;
|
|
||||||
AZStd::vector<CREGeomCache*, AZ::AZStdAlloc<CryLegacySTLAllocator>> m_geoms;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
CREGeomCache();
|
|
||||||
~CREGeomCache();
|
|
||||||
|
|
||||||
bool Update(const int flags, const bool bTesselation);
|
|
||||||
static void UpdateModified();
|
|
||||||
|
|
||||||
// CRendElementBase interface
|
|
||||||
virtual bool mfUpdate(int Flags, bool bTessellation);
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
// CREGeomCache interface
|
|
||||||
virtual void InitializeRenderElement(const uint numMeshes, _smart_ptr<IRenderMesh>* pMeshes, uint16 materialId);
|
|
||||||
virtual void SetupMotionBlur(CRenderObject* pRenderObject, const SRenderingPassInfo& passInfo);
|
|
||||||
|
|
||||||
virtual volatile int* SetAsyncUpdateState(int& threadId);
|
|
||||||
virtual DynArray<SMeshRenderData>* GetMeshFillDataPtr();
|
|
||||||
virtual DynArray<SMeshRenderData>* GetRenderDataPtr();
|
|
||||||
virtual void DisplayFilledBuffer(const int threadId);
|
|
||||||
|
|
||||||
|
|
||||||
AZ::Vertex::Format GetVertexFormat() const override;
|
|
||||||
bool GetGeometryInfo(SGeometryInfo &streams) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint16 m_materialId;
|
|
||||||
volatile bool m_bUpdateFrame[2];
|
|
||||||
volatile int m_transformUpdateState[2];
|
|
||||||
|
|
||||||
// We use a double buffered m_meshFillData array for input from the main thread. When data
|
|
||||||
// was successfully sent from the main thread it gets copied to m_meshRenderData
|
|
||||||
// This simplifies the cases where frame data is missing, e.g. meshFillData is not updated for a frame
|
|
||||||
// Note that meshFillData really needs to be double buffered because the copy occurs in render thread
|
|
||||||
// so the next main thread could already be touching the data again
|
|
||||||
//
|
|
||||||
// Note: m_meshRenderData is directly accessed for ray intersections via GetRenderDataPtr.
|
|
||||||
// This is safe, because it's only used in editor.
|
|
||||||
DynArray<SMeshRenderData> m_meshFillData[2];
|
|
||||||
DynArray<SMeshRenderData> m_meshRenderData;
|
|
||||||
|
|
||||||
static StaticInstance<UpdateList> sm_updateList[2]; // double buffered update lists
|
|
||||||
|
|
||||||
AZ::Vertex::Format m_geomCacheVertexFormat;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H
|
|
||||||
@ -1,194 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <IRenderer.h>
|
|
||||||
#include "Cry_Camera.h"
|
|
||||||
|
|
||||||
//================================================================================
|
|
||||||
|
|
||||||
struct SDynTexture2;
|
|
||||||
struct SDynTexture;
|
|
||||||
class IDynTexture;
|
|
||||||
class CameraViewParameters;
|
|
||||||
|
|
||||||
struct IImposterRenderElement
|
|
||||||
{
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow) = 0;
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sl) = 0;
|
|
||||||
virtual const SMinMaxBox& mfGetWorldSpaceBounds() = 0;
|
|
||||||
|
|
||||||
virtual bool IsSplit() = 0;
|
|
||||||
virtual bool IsScreenImposter() = 0;
|
|
||||||
|
|
||||||
virtual float GetRadiusX() = 0;
|
|
||||||
virtual float GetRadiusY() = 0;
|
|
||||||
virtual Vec3* GetQuadCorners() = 0;
|
|
||||||
virtual Vec3 GetNearPoint() = 0;
|
|
||||||
virtual Vec3 GetFarPoint() = 0;
|
|
||||||
virtual float GetErrorToleranceCosAngle() = 0;
|
|
||||||
virtual uint32 GetState() = 0;
|
|
||||||
virtual int GetAlphaRef() = 0;
|
|
||||||
virtual ColorF GetColorHelper() = 0;
|
|
||||||
virtual Vec3 GetLastSunDirection() = 0;
|
|
||||||
virtual uint8 GetLastBestEdge() = 0;
|
|
||||||
virtual float GetNear() = 0;
|
|
||||||
virtual float GetFar() = 0;
|
|
||||||
virtual float GetTransparency() = 0;
|
|
||||||
virtual Vec3 GetPosition();
|
|
||||||
virtual int GetLogResolutionX() = 0;
|
|
||||||
virtual int GetLogResolutionY() = 0;
|
|
||||||
virtual CameraViewParameters& GetLastViewParameters() = 0;
|
|
||||||
virtual IDynTexture* GetTexture() = 0;
|
|
||||||
virtual IDynTexture* GetScreenTexture() = 0;
|
|
||||||
virtual IDynTexture* GetFrontTexture() = 0;
|
|
||||||
virtual IDynTexture* GetDepthTexture() = 0;
|
|
||||||
virtual const SMinMaxBox& GetWorldSpaceBounds() = 0;
|
|
||||||
|
|
||||||
virtual void SetBBox(const Vec3& min, const Vec3& max) = 0;
|
|
||||||
virtual void SetScreenImposterState(bool state) = 0;
|
|
||||||
virtual void SetState(uint32 state) = 0;
|
|
||||||
virtual void SetAlphaRef(uint32 ref) = 0;
|
|
||||||
virtual void SetPosition(Vec3 pos) = 0;
|
|
||||||
virtual void SetFrameResetValue(int frameResetValue) = 0;
|
|
||||||
virtual void SetTexture(IDynTexture* texture) = 0;
|
|
||||||
virtual void SetScreenTexture(IDynTexture* texture) = 0;
|
|
||||||
virtual void SetFrontTexture(IDynTexture* texture) = 0;
|
|
||||||
virtual void SetDepthTexture(IDynTexture* texture) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CREImposter
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
friend class CRECloud;
|
|
||||||
static IDynTexture* m_pScreenTexture;
|
|
||||||
|
|
||||||
CameraViewParameters m_LastViewParameters;
|
|
||||||
bool m_bScreenImposter;
|
|
||||||
bool m_bSplit;
|
|
||||||
float m_fRadiusX;
|
|
||||||
float m_fRadiusY;
|
|
||||||
Vec3 m_vQuadCorners[4]; // in world space, relative to m_vPos, in clockwise order, can be rotated
|
|
||||||
Vec3 m_vNearPoint;
|
|
||||||
Vec3 m_vFarPoint;
|
|
||||||
int m_nLogResolutionX;
|
|
||||||
int m_nLogResolutionY;
|
|
||||||
IDynTexture* m_pTexture;
|
|
||||||
IDynTexture* m_pFrontTexture;
|
|
||||||
IDynTexture* m_pTextureDepth;
|
|
||||||
float m_fErrorToleranceCosAngle; // cosine of m_fErrorToleranceAngle used to check if IsImposterValid
|
|
||||||
SMinMaxBox m_WorldSpaceBV;
|
|
||||||
uint32 m_State;
|
|
||||||
int m_AlphaRef;
|
|
||||||
float m_fCurTransparency;
|
|
||||||
ColorF m_ColorHelper;
|
|
||||||
Vec3 m_vPos;
|
|
||||||
Vec3 m_vLastSunDir;
|
|
||||||
uint8 m_nLastBestEdge; // 0..11 this edge is favored to not jitter between different edges
|
|
||||||
float m_fNear;
|
|
||||||
float m_fFar;
|
|
||||||
|
|
||||||
bool IsImposterValid(const CameraViewParameters& viewParameters, float fRadiusX, float fRadiusY, float fCamRadiusX, float fCamRadiusY,
|
|
||||||
const int iRequiredLogResX, const int iRequiredLogResY, const uint32 dwBestEdge);
|
|
||||||
|
|
||||||
bool Display(bool bDisplayFrontOfSplit);
|
|
||||||
|
|
||||||
public:
|
|
||||||
int m_nFrameReset;
|
|
||||||
int m_FrameUpdate;
|
|
||||||
float m_fTimeUpdate;
|
|
||||||
|
|
||||||
static int m_MemUpdated;
|
|
||||||
static int m_MemPostponed;
|
|
||||||
static int m_PrevMemUpdated;
|
|
||||||
static int m_PrevMemPostponed;
|
|
||||||
|
|
||||||
CREImposter()
|
|
||||||
: CRendElementBase()
|
|
||||||
, m_pTexture(NULL)
|
|
||||||
, m_pFrontTexture(NULL)
|
|
||||||
, m_pTextureDepth(NULL)
|
|
||||||
, m_bSplit(false)
|
|
||||||
, m_fRadiusX(0)
|
|
||||||
, m_fRadiusY(0)
|
|
||||||
, m_fErrorToleranceCosAngle(cos(DEG2RAD(0.25f)))
|
|
||||||
, m_bScreenImposter(false)
|
|
||||||
, m_State(GS_DEPTHWRITE)
|
|
||||||
, m_AlphaRef(-1)
|
|
||||||
, m_fCurTransparency(1.0f)
|
|
||||||
, m_FrameUpdate(0)
|
|
||||||
, m_nFrameReset(0)
|
|
||||||
, m_fTimeUpdate(0)
|
|
||||||
, m_vLastSunDir(0, 0, 0)
|
|
||||||
, m_nLogResolutionX(0)
|
|
||||||
, m_nLogResolutionY(0)
|
|
||||||
, m_nLastBestEdge(0)
|
|
||||||
{
|
|
||||||
mfSetType(eDATA_Imposter);
|
|
||||||
mfUpdateFlags(FCEF_TRANSFORM);
|
|
||||||
m_ColorHelper = Col_White;
|
|
||||||
}
|
|
||||||
virtual ~CREImposter()
|
|
||||||
{
|
|
||||||
ReleaseResources();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UpdateImposter();
|
|
||||||
void ReleaseResources();
|
|
||||||
|
|
||||||
bool PrepareForUpdate();
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sl);
|
|
||||||
const SMinMaxBox& mfGetWorldSpaceBounds() { return m_WorldSpaceBV; }
|
|
||||||
|
|
||||||
virtual bool IsSplit() { return m_bSplit; }
|
|
||||||
virtual bool IsScreenImposter() { return m_bScreenImposter; }
|
|
||||||
|
|
||||||
virtual float GetRadiusX() { return m_fRadiusX; }
|
|
||||||
virtual float GetRadiusY() { return m_fRadiusY; }
|
|
||||||
virtual Vec3* GetQuadCorners() { return &m_vQuadCorners[0]; }
|
|
||||||
virtual Vec3 GetNearPoint() { return m_vNearPoint; }
|
|
||||||
virtual Vec3 GetFarPoint() { return m_vFarPoint; }
|
|
||||||
virtual float GetErrorToleranceCosAngle() { return m_fErrorToleranceCosAngle; }
|
|
||||||
virtual uint32 GetState() { return m_State; }
|
|
||||||
virtual int GetAlphaRef() { return m_AlphaRef; }
|
|
||||||
virtual ColorF GetColorHelper() { return m_ColorHelper; }
|
|
||||||
virtual Vec3 GetLastSunDirection() { return m_vLastSunDir; }
|
|
||||||
virtual uint8 GetLastBestEdge() { return m_nLastBestEdge; }
|
|
||||||
virtual float GetNear() { return m_fNear; }
|
|
||||||
virtual float GetFar() { return m_fFar; }
|
|
||||||
virtual float GetTransparency() { return m_fCurTransparency; }
|
|
||||||
virtual Vec3 GetPosition();
|
|
||||||
virtual int GetLogResolutionX() { return m_nLogResolutionX; }
|
|
||||||
virtual int GetLogResolutionY() { return m_nLogResolutionY; }
|
|
||||||
virtual CameraViewParameters& GetLastViewParameters() { return m_LastViewParameters; }
|
|
||||||
virtual IDynTexture** GetTexture() { return &m_pTexture; }
|
|
||||||
virtual IDynTexture** GetScreenTexture() { return &m_pScreenTexture; }
|
|
||||||
virtual IDynTexture** GetFrontTexture() { return &m_pFrontTexture; }
|
|
||||||
virtual IDynTexture** GetDepthTexture() { return &m_pTextureDepth; }
|
|
||||||
virtual const SMinMaxBox& GetWorldSpaceBounds() { return m_WorldSpaceBV; }
|
|
||||||
virtual int GetFrameReset() { return m_nFrameReset; }
|
|
||||||
virtual void SetBBox(const Vec3& min, const Vec3& max) { m_WorldSpaceBV.SetMin(min); m_WorldSpaceBV.SetMax(max); }
|
|
||||||
virtual void SetScreenImposterState(bool state) { m_bScreenImposter = state; }
|
|
||||||
virtual void SetState(uint32 state) { m_State = state; }
|
|
||||||
virtual void SetAlphaRef(uint32 ref) { m_AlphaRef = ref; }
|
|
||||||
virtual void SetPosition(Vec3 pos) { m_vPos = pos; }
|
|
||||||
virtual void SetFrameResetValue(int frameResetValue) { m_nFrameReset = frameResetValue; }
|
|
||||||
};
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef __CREMESH_H__
|
|
||||||
#define __CREMESH_H__
|
|
||||||
|
|
||||||
class CREMesh
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
struct CRenderChunk* m_pChunk;
|
|
||||||
class CRenderMesh* m_pRenderMesh;
|
|
||||||
|
|
||||||
// Copy of Chunk to avoid indirections
|
|
||||||
int32 m_nFirstIndexId;
|
|
||||||
int32 m_nNumIndices;
|
|
||||||
|
|
||||||
uint32 m_nFirstVertId;
|
|
||||||
uint32 m_nNumVerts;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CREMesh()
|
|
||||||
{
|
|
||||||
mfSetType(eDATA_Mesh);
|
|
||||||
mfUpdateFlags(FCEF_TRANSFORM);
|
|
||||||
|
|
||||||
m_pChunk = NULL;
|
|
||||||
m_pRenderMesh = NULL;
|
|
||||||
m_nFirstIndexId = -1;
|
|
||||||
m_nNumIndices = -1;
|
|
||||||
m_nFirstVertId = 0;
|
|
||||||
m_nNumVerts = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~CREMesh()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ideally should be declared and left unimplemented to prevent slicing at compile time
|
|
||||||
// but this would prevent auto code gen in renderer later on.
|
|
||||||
// To track potential slicing, uncomment the following (and their equivalent in CREMeshImpl)
|
|
||||||
//CREMesh(CREMesh&);
|
|
||||||
//CREMesh& operator=(CREMesh& rhs);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __CREMESH_H__
|
|
||||||
@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef __CREOCCLUSIONQUERY_H__
|
|
||||||
#define __CREOCCLUSIONQUERY_H__
|
|
||||||
|
|
||||||
#define SUPP_HMAP_OCCL
|
|
||||||
#define SUPP_HWOBJ_OCCL
|
|
||||||
|
|
||||||
//=============================================================
|
|
||||||
|
|
||||||
class CRenderMesh;
|
|
||||||
|
|
||||||
class CREOcclusionQuery
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
friend class CRender3D;
|
|
||||||
bool m_bSucceeded;
|
|
||||||
public:
|
|
||||||
|
|
||||||
int m_nVisSamples;
|
|
||||||
int m_nCheckFrame;
|
|
||||||
int m_nDrawFrame;
|
|
||||||
Vec3 m_vBoxMin;
|
|
||||||
Vec3 m_vBoxMax;
|
|
||||||
|
|
||||||
UINT_PTR m_nOcclusionID; // this will carry a pointer LPDIRECT3DQUERY9, so it needs to be 64-bit on Windows 64
|
|
||||||
|
|
||||||
CRenderMesh* m_pRMBox;
|
|
||||||
static uint32 m_nQueriesPerFrameCounter;
|
|
||||||
static uint32 m_nReadResultNowCounter;
|
|
||||||
static uint32 m_nReadResultTryCounter;
|
|
||||||
|
|
||||||
CREOcclusionQuery()
|
|
||||||
{
|
|
||||||
m_nOcclusionID = 0;
|
|
||||||
|
|
||||||
m_nVisSamples = 800 * 600;
|
|
||||||
m_nCheckFrame = 0;
|
|
||||||
m_nDrawFrame = 0;
|
|
||||||
m_vBoxMin = Vec3(0, 0, 0);
|
|
||||||
m_vBoxMax = Vec3(0, 0, 0);
|
|
||||||
m_pRMBox = NULL;
|
|
||||||
|
|
||||||
mfSetType(eDATA_OcclusionQuery);
|
|
||||||
mfUpdateFlags(FCEF_TRANSFORM);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RT_ReadResult_Try(uint32 nDefaultNumSamples);
|
|
||||||
|
|
||||||
ILINE bool HasSucceeded() const { return m_bSucceeded; }
|
|
||||||
|
|
||||||
virtual ~CREOcclusionQuery();
|
|
||||||
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
virtual void mfReset();
|
|
||||||
virtual bool mfReadResult_Try(uint32 nDefaultNumSamples = 1);
|
|
||||||
virtual bool mfReadResult_Now();
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct OcclusionTestClient
|
|
||||||
{
|
|
||||||
OcclusionTestClient()
|
|
||||||
: nLastOccludedMainFrameID(0)
|
|
||||||
, nLastVisibleMainFrameID(0)
|
|
||||||
{
|
|
||||||
#ifdef SUPP_HMAP_OCCL
|
|
||||||
vLastVisPoint.Set(0, 0, 0);
|
|
||||||
nTerrainOccLastFrame = 0;
|
|
||||||
#endif
|
|
||||||
#ifdef SUPP_HWOBJ_OCCL
|
|
||||||
bOccluded = true;
|
|
||||||
pREOcclusionQuery = 0;
|
|
||||||
#endif
|
|
||||||
//nInstantTestRequested=0;
|
|
||||||
}
|
|
||||||
#ifdef SUPP_HWOBJ_OCCL
|
|
||||||
~OcclusionTestClient()
|
|
||||||
{
|
|
||||||
if (pREOcclusionQuery)
|
|
||||||
{
|
|
||||||
pREOcclusionQuery->Release(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
uint32 nLastVisibleMainFrameID, nLastOccludedMainFrameID;
|
|
||||||
uint32 nLastShadowCastMainFrameID, nLastNoShadowCastMainFrameID;
|
|
||||||
#ifdef SUPP_HMAP_OCCL
|
|
||||||
Vec3 vLastVisPoint;
|
|
||||||
int nTerrainOccLastFrame;
|
|
||||||
#endif
|
|
||||||
#ifdef SUPP_HWOBJ_OCCL
|
|
||||||
CREOcclusionQuery* pREOcclusionQuery;
|
|
||||||
uint8 bOccluded;
|
|
||||||
#endif
|
|
||||||
//uint8 nInstantTestRequested;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_CREOCCLUSIONQUERY_H
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
class CREPostProcess
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
friend class CD3D9Renderer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
CREPostProcess();
|
|
||||||
virtual ~CREPostProcess();
|
|
||||||
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
// Use for setting numeric values, vec4 (colors, position, vectors, wtv), strings
|
|
||||||
virtual int mfSetParameter(const char* pszParam, float fValue, bool bForceValue = false) const;
|
|
||||||
virtual int mfSetParameterVec4(const char* pszParam, const Vec4& pValue, bool bForceValue = false) const;
|
|
||||||
virtual int mfSetParameterString(const char* pszParam, const char* pszArg) const;
|
|
||||||
|
|
||||||
virtual void mfGetParameter(const char* pszParam, float& fValue) const;
|
|
||||||
virtual void mfGetParameterVec4(const char* pszParam, Vec4& pValue) const;
|
|
||||||
virtual void mfGetParameterString(const char* pszParam, const char*& pszArg) const;
|
|
||||||
|
|
||||||
virtual int32 mfGetPostEffectID(const char* pPostEffectName) const;
|
|
||||||
|
|
||||||
// Reset all post processing effects
|
|
||||||
virtual void Reset(bool bOnSpecChange = false);
|
|
||||||
virtual void mfReset()
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
#ifndef _CREPRISMOBJECT_
|
|
||||||
#define _CREPRISMOBJECT_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#if !defined(EXCLUDE_DOCUMENTATION_PURPOSE)
|
|
||||||
|
|
||||||
class CREPrismObject
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CREPrismObject();
|
|
||||||
|
|
||||||
virtual ~CREPrismObject() {}
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 m_center;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EXCLUDE_DOCUMENTATION_PURPOSE
|
|
||||||
|
|
||||||
#endif // _CREPRISMOBJECT_
|
|
||||||
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef __CRESKY_H__
|
|
||||||
#define __CRESKY_H__
|
|
||||||
|
|
||||||
//=============================================================
|
|
||||||
|
|
||||||
#include "VertexFormats.h"
|
|
||||||
#include <Vertex.h>
|
|
||||||
|
|
||||||
struct SSkyLightRenderParams;
|
|
||||||
|
|
||||||
class CRESky
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
friend class CRender3D;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
float m_fTerrainWaterLevel;
|
|
||||||
float m_fSkyBoxStretching;
|
|
||||||
float m_fAlpha;
|
|
||||||
int m_nSphereListId;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CRESky();
|
|
||||||
virtual ~CRESky();
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
AZ::Vertex::Format GetVertexFormat() const override;
|
|
||||||
bool GetGeometryInfo(SGeometryInfo& streams) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
AZ::Vertex::Format m_skyVertexFormat;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CREHDRSky
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CREHDRSky();
|
|
||||||
virtual ~CREHDRSky();
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenerateSkyDomeTextures(int32 width, int32 height);
|
|
||||||
|
|
||||||
virtual AZ::Vertex::Format GetVertexFormat() const override;
|
|
||||||
virtual bool GetGeometryInfo(SGeometryInfo& streams) override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
const SSkyLightRenderParams* m_pRenderParams;
|
|
||||||
int m_moonTexId;
|
|
||||||
class CTexture* m_pSkyDomeTextureMie;
|
|
||||||
class CTexture* m_pSkyDomeTextureRayleigh;
|
|
||||||
|
|
||||||
static void SetCommonMoonParams(CShader* ef, bool bUseMoon = false);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_skyDomeTextureLastTimeStamp;
|
|
||||||
int m_frameReset;
|
|
||||||
class CStars* m_pStars;
|
|
||||||
AZ::Vertex::Format m_hdrSkyVertexFormat;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __CRESKY_H__
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
#ifndef _CREVOLUMEOBJECT_
|
|
||||||
#define _CREVOLUMEOBJECT_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "VertexFormats.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct IVolumeObjectRenderNode;
|
|
||||||
|
|
||||||
struct IVolumeTexture
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~IVolumeTexture() {}
|
|
||||||
virtual void Release() = 0;
|
|
||||||
virtual bool Create(unsigned int width, unsigned int height, unsigned int depth, unsigned char* pData) = 0;
|
|
||||||
virtual bool Update(unsigned int width, unsigned int height, unsigned int depth, const unsigned char* pData) = 0;
|
|
||||||
virtual int GetTexID() const = 0;
|
|
||||||
virtual uint32 GetWidth() const = 0;
|
|
||||||
virtual uint32 GetHeight() const = 0;
|
|
||||||
virtual uint32 GetDepth() const = 0;
|
|
||||||
virtual ITexture* GetTexture() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CREVolumeObject
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CREVolumeObject();
|
|
||||||
|
|
||||||
virtual ~CREVolumeObject();
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
|
|
||||||
virtual IVolumeTexture* CreateVolumeTexture() const;
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 m_center;
|
|
||||||
Matrix34 m_matInv;
|
|
||||||
Vec3 m_eyePosInWS;
|
|
||||||
Vec3 m_eyePosInOS;
|
|
||||||
Plane_tpl<f32> m_volumeTraceStartPlane;
|
|
||||||
AABB m_renderBoundsOS;
|
|
||||||
bool m_viewerInsideVolume;
|
|
||||||
bool m_nearPlaneIntersectsVolume;
|
|
||||||
float m_alpha;
|
|
||||||
float m_scale;
|
|
||||||
|
|
||||||
IVolumeTexture* m_pDensVol;
|
|
||||||
IVolumeTexture* m_pShadVol;
|
|
||||||
_smart_ptr<IRenderMesh> m_pHullMesh;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // #ifndef _CREVOLUMEOBJECT_
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef _CREWATEROCEAN_
|
|
||||||
#define _CREWATEROCEAN_
|
|
||||||
|
|
||||||
class CWater;
|
|
||||||
|
|
||||||
class CREWaterOcean
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CREWaterOcean();
|
|
||||||
virtual ~CREWaterOcean();
|
|
||||||
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
virtual void mfGetPlane(Plane_tpl<f32>& pl);
|
|
||||||
|
|
||||||
virtual void Create(uint32 nVerticesCount, SVF_P3F_C4B_T2F* pVertices, uint32 nIndicesCount, const void* pIndices, uint32 nIndexSizeof);
|
|
||||||
void ReleaseOcean();
|
|
||||||
|
|
||||||
virtual Vec3 GetPositionAt(float x, float y) const;
|
|
||||||
virtual Vec4* GetDisplaceGrid() const;
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
|
|
||||||
uint32 m_nVerticesCount;
|
|
||||||
uint32 m_nIndicesCount;
|
|
||||||
uint32 m_nIndexSizeof;
|
|
||||||
|
|
||||||
void* m_pVertDecl;
|
|
||||||
void* m_pVertices;
|
|
||||||
void* m_pIndices;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void UpdateFFT();
|
|
||||||
void FrameUpdate();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
#ifndef _CREWATERVOLUME_
|
|
||||||
#define _CREWATERVOLUME_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "VertexFormats.h"
|
|
||||||
|
|
||||||
class CREWaterVolume
|
|
||||||
: public CRendElementBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CREWaterVolume();
|
|
||||||
|
|
||||||
virtual ~CREWaterVolume();
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow);
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
|
||||||
virtual void mfGetPlane(Plane_tpl<f32>& pl);
|
|
||||||
virtual void mfCenter(Vec3& vCenter, CRenderObject* pObj);
|
|
||||||
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
|
||||||
{
|
|
||||||
pSizer->AddObject(this, sizeof(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
struct SParams
|
|
||||||
{
|
|
||||||
SParams()
|
|
||||||
: m_pVertices(0)
|
|
||||||
, m_pIndices(0)
|
|
||||||
, m_numVertices(0)
|
|
||||||
, m_numIndices(0)
|
|
||||||
, m_center(0, 0, 0)
|
|
||||||
, m_WSBBox(Vec3(-1, -1, -1), Vec3(1, 1, 1))
|
|
||||||
, m_fogPlane(Vec3(0, 0, 1), 0)
|
|
||||||
, m_fogDensity(0.1f)
|
|
||||||
, m_fogColor(0.2f, 0.5f, 0.7f)
|
|
||||||
, m_fogColorAffectedBySun(true)
|
|
||||||
, m_fogShadowing(0.5f)
|
|
||||||
, m_caustics(true)
|
|
||||||
, m_causticIntensity(1.0f)
|
|
||||||
, m_causticTiling(1.0f)
|
|
||||||
, m_causticHeight(0.9f)
|
|
||||||
, m_viewerInsideVolume(false)
|
|
||||||
, m_viewerCloseToWaterPlane(false)
|
|
||||||
, m_viewerCloseToWaterVolume(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const SVF_P3F_C4B_T2F* m_pVertices;
|
|
||||||
const uint16* m_pIndices;
|
|
||||||
|
|
||||||
size_t m_numVertices;
|
|
||||||
size_t m_numIndices;
|
|
||||||
|
|
||||||
Vec3 m_center;
|
|
||||||
AABB m_WSBBox;
|
|
||||||
|
|
||||||
Plane_tpl<f32> m_fogPlane;
|
|
||||||
float m_fogDensity;
|
|
||||||
Vec3 m_fogColor;
|
|
||||||
bool m_fogColorAffectedBySun;
|
|
||||||
float m_fogShadowing;
|
|
||||||
|
|
||||||
bool m_caustics;
|
|
||||||
float m_causticIntensity;
|
|
||||||
float m_causticTiling;
|
|
||||||
float m_causticHeight;
|
|
||||||
|
|
||||||
bool m_viewerInsideVolume;
|
|
||||||
bool m_viewerCloseToWaterPlane;
|
|
||||||
bool m_viewerCloseToWaterVolume;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SOceanParams
|
|
||||||
{
|
|
||||||
SOceanParams()
|
|
||||||
: m_fogColor(0.2f, 0.5f, 0.7f)
|
|
||||||
, m_fogColorShallow(0.2f, 0.5f, 0.7f)
|
|
||||||
, m_fogDensity(0.2f)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 m_fogColor;
|
|
||||||
Vec3 m_fogColorShallow;
|
|
||||||
float m_fogDensity;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
const SParams* m_pParams;
|
|
||||||
const SOceanParams* m_pOceanParams;
|
|
||||||
bool m_drawWaterSurface;
|
|
||||||
bool m_drawFastPath;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef _CREWATERVOLUME_
|
|
||||||
@ -1,286 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Interface to the Mini GUI subsystem
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_ICRYMINIGUI_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_ICRYMINIGUI_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include <smartptr.h>
|
|
||||||
#include <Cry_Color.h>
|
|
||||||
#include <CryExtension/ICryUnknown.h>
|
|
||||||
|
|
||||||
namespace minigui
|
|
||||||
{
|
|
||||||
struct IMiniCtrl;
|
|
||||||
|
|
||||||
// Rectangle class
|
|
||||||
struct Rect
|
|
||||||
{
|
|
||||||
float left;
|
|
||||||
float top;
|
|
||||||
float right;
|
|
||||||
float bottom;
|
|
||||||
|
|
||||||
Rect()
|
|
||||||
: left(0)
|
|
||||||
, top(0)
|
|
||||||
, right(0)
|
|
||||||
, bottom(0) {}
|
|
||||||
Rect(float l, float t, float r, float b)
|
|
||||||
: left(l)
|
|
||||||
, top(t)
|
|
||||||
, right(r)
|
|
||||||
, bottom(b) {}
|
|
||||||
Rect(const Rect& rc) { left = rc.left; top = rc.top; right = rc.right; bottom = rc.bottom; }
|
|
||||||
bool IsPointInside(float x, float y) const { return x >= left && x <= right && y >= top && y <= bottom; }
|
|
||||||
float Width() const { return right - left; }
|
|
||||||
float Height() const { return bottom - top; }
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void(* ClickCallback)(void* data, bool onOff);
|
|
||||||
typedef void(* RenderCallback)(float x, float y);
|
|
||||||
|
|
||||||
enum EMiniCtrlStatus
|
|
||||||
{
|
|
||||||
eCtrl_Hidden = BIT(0), // Control is hidden.
|
|
||||||
eCtrl_Highlight = BIT(1), // Control is highlight (probably mouse over).
|
|
||||||
eCtrl_Focus = BIT(2), // Control have focus (from keyboard).
|
|
||||||
eCtrl_Checked = BIT(3), // Control have checked mark.
|
|
||||||
eCtrl_NoBorder = BIT(4), // Control have no border.
|
|
||||||
eCtrl_CheckButton = BIT(5), // Button control behave as a check button.
|
|
||||||
eCtrl_TextAlignCentre = BIT(6), // Draw text aligned centre
|
|
||||||
eCtrl_AutoResize = BIT(7), // Auto resize depending on text length
|
|
||||||
eCtrl_Moveable = BIT(8), // Dynamically reposition ctrl
|
|
||||||
eCtrl_CloseButton = BIT(9), // Control has close button
|
|
||||||
};
|
|
||||||
enum EMiniCtrlEvent
|
|
||||||
{
|
|
||||||
eCtrlEvent_LButtonDown = BIT(0),
|
|
||||||
eCtrlEvent_LButtonUp = BIT(1),
|
|
||||||
eCtrlEvent_LButtonPressed = BIT(2),
|
|
||||||
eCtrlEvent_MouseOver = BIT(3),
|
|
||||||
eCtrlEvent_MouseOff = BIT(4),
|
|
||||||
eCtrlEvent_DPadLeft = BIT(5),
|
|
||||||
eCtrlEvent_DPadRight = BIT(6),
|
|
||||||
eCtrlEvent_DPadUp = BIT(7),
|
|
||||||
eCtrlEvent_DPadDown = BIT(8),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Types of the supported controls
|
|
||||||
enum EMiniCtrlType
|
|
||||||
{
|
|
||||||
eCtrlType_Unknown = 0,
|
|
||||||
eCtrlType_Button,
|
|
||||||
eCtrlType_Menu,
|
|
||||||
eCtrlType_InfoBox,
|
|
||||||
eCtrlType_Table,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SMetrics
|
|
||||||
{
|
|
||||||
float fTextSize;
|
|
||||||
float fTitleSize;
|
|
||||||
|
|
||||||
// Colors.
|
|
||||||
ColorB clrFrameBorder;
|
|
||||||
ColorB clrFrameBorderHighlight;
|
|
||||||
ColorB clrFrameBorderOutOfFocus;
|
|
||||||
ColorB clrChecked;
|
|
||||||
ColorB clrBackground;
|
|
||||||
ColorB clrBackgroundHighlight;
|
|
||||||
ColorB clrBackgroundSelected;
|
|
||||||
ColorB clrTitle;
|
|
||||||
ColorB clrText;
|
|
||||||
ColorB clrTextSelected;
|
|
||||||
|
|
||||||
uint8 outOfFocusAlpha;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ECommand
|
|
||||||
{
|
|
||||||
eCommand_ButtonPress,
|
|
||||||
eCommand_ButtonChecked,
|
|
||||||
eCommand_ButtonUnchecked,
|
|
||||||
};
|
|
||||||
// Command sent from the control.
|
|
||||||
struct SCommand
|
|
||||||
{
|
|
||||||
ECommand command;
|
|
||||||
IMiniCtrl* pCtrl;
|
|
||||||
int nCtrlID;
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Event listener interface for the MiniGUI
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
struct IMiniGUIEventListener
|
|
||||||
{
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual ~IMiniGUIEventListener(){}
|
|
||||||
virtual void OnCommand(SCommand& cmd) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
// Interface to the GUI
|
|
||||||
struct IMiniGUI
|
|
||||||
: public ICryUnknown
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CRYINTERFACE_DECLARE(IMiniGUI, 0xea09d34268814f2a, 0xaf1034e04b076011);
|
|
||||||
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual void Init() = 0;
|
|
||||||
virtual void Done() = 0;
|
|
||||||
virtual void Draw() = 0;
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
|
|
||||||
virtual void SaveState() = 0;
|
|
||||||
virtual void RestoreState() = 0;
|
|
||||||
|
|
||||||
virtual void SetEnabled(bool status) = 0;
|
|
||||||
virtual void SetInFocus(bool status) = 0;
|
|
||||||
virtual bool InFocus() = 0;
|
|
||||||
|
|
||||||
virtual void SetEventListener(IMiniGUIEventListener* pListener) = 0;
|
|
||||||
|
|
||||||
virtual SMetrics& Metrics() = 0;
|
|
||||||
|
|
||||||
// Makes a new control
|
|
||||||
virtual IMiniCtrl* CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title) = 0;
|
|
||||||
|
|
||||||
// Remove all controls.
|
|
||||||
virtual void RemoveAllCtrl() = 0;
|
|
||||||
|
|
||||||
virtual void OnCommand(SCommand& cmd) = 0;
|
|
||||||
|
|
||||||
virtual IMiniCtrl* GetCtrlFromPoint(float x, float y) const = 0;
|
|
||||||
|
|
||||||
virtual void SetMovingCtrl(IMiniCtrl* pCtrl) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
DECLARE_SMART_POINTERS(IMiniGUI);
|
|
||||||
|
|
||||||
struct IMiniCtrl
|
|
||||||
: public _reference_target_t
|
|
||||||
{
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
|
|
||||||
virtual void SaveState() = 0;
|
|
||||||
virtual void RestoreState() = 0;
|
|
||||||
|
|
||||||
// For system call only.
|
|
||||||
virtual void SetGUI(IMiniGUI* pGUI) = 0;
|
|
||||||
virtual IMiniGUI* GetGUI() const = 0;
|
|
||||||
|
|
||||||
virtual EMiniCtrlType GetType() const = 0;
|
|
||||||
|
|
||||||
virtual int GetId() const = 0;
|
|
||||||
virtual void SetId(int id) = 0;
|
|
||||||
|
|
||||||
virtual const char* GetTitle() const = 0;
|
|
||||||
virtual void SetTitle(const char* title) = 0;
|
|
||||||
|
|
||||||
virtual Rect GetRect() const = 0;
|
|
||||||
virtual void SetRect(const Rect& rc) = 0;
|
|
||||||
|
|
||||||
virtual void SetFlag(uint32 flag) = 0;
|
|
||||||
virtual void ClearFlag(uint32 flag) = 0;
|
|
||||||
virtual bool CheckFlag(uint32 flag) const = 0;
|
|
||||||
|
|
||||||
// Sub Controls handling.
|
|
||||||
virtual void AddSubCtrl(IMiniCtrl* pCtrl) = 0;
|
|
||||||
virtual void RemoveSubCtrl(IMiniCtrl* pCtrl) = 0;
|
|
||||||
virtual void RemoveAllSubCtrl() = 0;
|
|
||||||
virtual int GetSubCtrlCount() const = 0;
|
|
||||||
virtual IMiniCtrl* GetSubCtrl(int nIndex) const = 0;
|
|
||||||
virtual IMiniCtrl* GetParent() const = 0;
|
|
||||||
|
|
||||||
// Check if point is inside any of the sub controls.
|
|
||||||
virtual IMiniCtrl* GetCtrlFromPoint(float x, float y) = 0;
|
|
||||||
|
|
||||||
virtual void OnPaint(class CDrawContext& dc) = 0;
|
|
||||||
|
|
||||||
virtual void SetVisible(bool state) = 0;
|
|
||||||
|
|
||||||
// Events from GUI
|
|
||||||
virtual void OnEvent([[maybe_unused]] float x, [[maybe_unused]] float y, EMiniCtrlEvent) {};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// When set, this control will be enabling/disabling specified cvar
|
|
||||||
// when button not checked fOffValue will be set on cvar, when checked fOnValue will be set.
|
|
||||||
virtual bool SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue) = 0;
|
|
||||||
|
|
||||||
virtual bool SetClickCallback(ClickCallback callback, void* pCallbackData) = 0;
|
|
||||||
|
|
||||||
virtual bool SetRenderCallback(RenderCallback callback) = 0;
|
|
||||||
|
|
||||||
virtual bool SetConnectedCtrl(IMiniCtrl* pConnectedCtrl) = 0;
|
|
||||||
|
|
||||||
//resize text box based what text is present
|
|
||||||
virtual void AutoResize() = 0;
|
|
||||||
|
|
||||||
//Create close 'X' button for control
|
|
||||||
virtual void CreateCloseButton() = 0;
|
|
||||||
|
|
||||||
//Move control
|
|
||||||
virtual void Move(float x, float y) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
typedef _smart_ptr<IMiniCtrl> IMiniCtrlPtr;
|
|
||||||
|
|
||||||
class IMiniGuiCommon
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual ~IMiniGuiCommon(){}
|
|
||||||
virtual bool IsHidden() = 0;
|
|
||||||
virtual void Hide(bool stat) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
class IMiniTable
|
|
||||||
: public IMiniGuiCommon
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual int AddColumn(const char* name) = 0;
|
|
||||||
virtual void RemoveColumns() = 0;
|
|
||||||
virtual int AddData(int columnIndex, ColorB col, const char* format, ...) = 0;
|
|
||||||
virtual void ClearTable() = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
class IMiniInfoBox
|
|
||||||
: public IMiniGuiCommon
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual void SetTextIndent(float x) = 0;
|
|
||||||
virtual void SetTextSize(float sz) = 0;
|
|
||||||
virtual void ClearEntries() = 0;
|
|
||||||
virtual void AddEntry(const char* str, ColorB col, float textSize) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define MINIGUI_BEGIN namespace minigui {
|
|
||||||
#define MINIGUI_END }
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_ICRYMINIGUI_H
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_IDEFERREDCOLLISIONEVENT_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_IDEFERREDCOLLISIONEVENT_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include <IThreadTask.h>
|
|
||||||
|
|
||||||
struct EventPhys;
|
|
||||||
|
|
||||||
// Base class for all deferred physics events
|
|
||||||
// Basically this class works like a future,
|
|
||||||
// Start() start the computation(some in the main thread, major part in a task/job)
|
|
||||||
// Result() will sync the task operation and return the result
|
|
||||||
struct IDeferredPhysicsEvent
|
|
||||||
: public IThreadTask
|
|
||||||
{
|
|
||||||
// enum list of all types of deferred events
|
|
||||||
enum DeferredEventType
|
|
||||||
{
|
|
||||||
PhysCallBack_OnCollision
|
|
||||||
};
|
|
||||||
|
|
||||||
IDeferredPhysicsEvent(){}
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual ~IDeferredPhysicsEvent(){}
|
|
||||||
|
|
||||||
// == "future" like interface == //
|
|
||||||
|
|
||||||
// start the execution of the event
|
|
||||||
virtual void Start() = 0;
|
|
||||||
|
|
||||||
// sync the event and do all necessary post-processing, then return the result
|
|
||||||
virtual int Result(EventPhys* pOrigEvent = 0) = 0;
|
|
||||||
|
|
||||||
// just wait for the event to finish
|
|
||||||
virtual void Sync() = 0;
|
|
||||||
|
|
||||||
// check if the async computation part has finished
|
|
||||||
virtual bool HasFinished() = 0;
|
|
||||||
|
|
||||||
// Get the concrete Type of this deferred event
|
|
||||||
virtual DeferredEventType GetType() const = 0;
|
|
||||||
|
|
||||||
// returns a ptr to the original physics event
|
|
||||||
virtual EventPhys* PhysicsEvent() = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Manager class for deferred physics events
|
|
||||||
struct IDeferredPhysicsEventManager
|
|
||||||
{
|
|
||||||
// type of create function used to create needed deferred events in the HandleEvent function
|
|
||||||
typedef IDeferredPhysicsEvent*(* CreateEventFunc)(const EventPhys* pEvent);
|
|
||||||
|
|
||||||
IDeferredPhysicsEventManager(){}
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual ~IDeferredPhysicsEventManager(){}
|
|
||||||
|
|
||||||
// dispatch an deferred event to the task thread
|
|
||||||
virtual void DispatchDeferredEvent(IDeferredPhysicsEvent* pEvent) = 0;
|
|
||||||
|
|
||||||
// Encapsulates common logic for deferred events, should be called from the physics callbacks
|
|
||||||
// handles the cvar management as well as deferred event creating
|
|
||||||
virtual int HandleEvent(const EventPhys* pEvent, IDeferredPhysicsEventManager::CreateEventFunc, IDeferredPhysicsEvent::DeferredEventType) = 0;
|
|
||||||
|
|
||||||
// Register and Unregister Deferred events in the manager to allow
|
|
||||||
virtual void RegisterDeferredEvent(IDeferredPhysicsEvent* pDeferredEvent) = 0;
|
|
||||||
virtual void UnRegisterDeferredEvent(IDeferredPhysicsEvent* pDeferredEvent) = 0;
|
|
||||||
|
|
||||||
// Delete all Deferred Events in flight, use only when also clearing the physics event queue
|
|
||||||
// or else this call results in dangling points, mostly used for save/load
|
|
||||||
virtual void ClearDeferredEvents() = 0;
|
|
||||||
|
|
||||||
virtual void Update() = 0;
|
|
||||||
|
|
||||||
virtual IDeferredPhysicsEvent* GetLastCollisionEventForEntity(IPhysicalEntity* pPhysEnt) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_IDEFERREDCOLLISIONEVENT_H
|
|
||||||
@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_IDEFRAGALLOCATOR_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_IDEFRAGALLOCATOR_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
struct IDefragAllocatorStats
|
|
||||||
{
|
|
||||||
size_t nCapacity;
|
|
||||||
size_t nInUseSize;
|
|
||||||
uint32 nInUseBlocks;
|
|
||||||
uint32 nFreeBlocks;
|
|
||||||
uint32 nPinnedBlocks;
|
|
||||||
uint32 nMovingBlocks;
|
|
||||||
uint32 nLargestFreeBlockSize;
|
|
||||||
uint32 nSmallestFreeBlockSize;
|
|
||||||
uint32 nMeanFreeBlockSize;
|
|
||||||
uint32 nCancelledMoveCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IDefragAllocatorCopyNotification
|
|
||||||
{
|
|
||||||
IDefragAllocatorCopyNotification()
|
|
||||||
: bDstIsValid(false)
|
|
||||||
, bSrcIsUnneeded(false)
|
|
||||||
, bCancel(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bDstIsValid;
|
|
||||||
bool bSrcIsUnneeded;
|
|
||||||
|
|
||||||
// Flag to indicate that the copy can't be initiated after all - currently only cancelling before a relocate
|
|
||||||
// is begun is supported, and the destination region must be stable
|
|
||||||
bool bCancel;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IDefragAllocatorPolicy
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
InvalidUserMoveId = 0xffffffff
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual uint32 BeginCopy(void* pContext, UINT_PTR dstOffset, UINT_PTR srcOffset, UINT_PTR size, IDefragAllocatorCopyNotification* pNotification) = 0;
|
|
||||||
virtual void Relocate(uint32 userMoveId, void* pContext, UINT_PTR newOffset, UINT_PTR oldOffset, UINT_PTR size) = 0;
|
|
||||||
virtual void CancelCopy(uint32 userMoveId, void* pContext, bool bSync) = 0;
|
|
||||||
|
|
||||||
// Perform the copy and relocate immediately - will only be called when UnAppendSegment is
|
|
||||||
virtual void SyncCopy(void* pContext, UINT_PTR dstOffset, UINT_PTR srcOffset, UINT_PTR size) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~IDefragAllocatorPolicy() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class IDefragAllocator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef uint32 Hdl;
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
InvalidHdl = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AllocatePinnedResult
|
|
||||||
{
|
|
||||||
Hdl hdl;
|
|
||||||
UINT_PTR offs;
|
|
||||||
UINT_PTR usableSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum EBlockSearchKind
|
|
||||||
{
|
|
||||||
eBSK_BestFit,
|
|
||||||
eBSK_FirstFit
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Policy
|
|
||||||
{
|
|
||||||
Policy()
|
|
||||||
: pDefragPolicy(NULL)
|
|
||||||
, maxAllocs(0)
|
|
||||||
, maxSegments(1)
|
|
||||||
, blockSearchKind(eBSK_BestFit)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
IDefragAllocatorPolicy* pDefragPolicy;
|
|
||||||
size_t maxAllocs;
|
|
||||||
size_t maxSegments;
|
|
||||||
EBlockSearchKind blockSearchKind;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual void Release(bool bDiscard = false) = 0;
|
|
||||||
|
|
||||||
virtual void Init(UINT_PTR capacity, UINT_PTR alignment, const Policy& policy = Policy()) = 0;
|
|
||||||
|
|
||||||
virtual bool AppendSegment(UINT_PTR capacity) = 0;
|
|
||||||
virtual void UnAppendSegment() = 0;
|
|
||||||
|
|
||||||
virtual Hdl Allocate(size_t sz, const char* source, void* pContext = NULL) = 0;
|
|
||||||
virtual Hdl AllocateAligned(size_t sz, size_t alignment, const char* source, void* pContext = NULL) = 0;
|
|
||||||
virtual AllocatePinnedResult AllocatePinned(size_t sz, const char* source, void* pContext = NULL) = 0;
|
|
||||||
virtual bool Free(Hdl hdl) = 0;
|
|
||||||
|
|
||||||
virtual void ChangeContext(Hdl hdl, void* pNewContext) = 0;
|
|
||||||
|
|
||||||
virtual size_t GetAllocated() const = 0;
|
|
||||||
virtual IDefragAllocatorStats GetStats() = 0;
|
|
||||||
|
|
||||||
virtual void DisplayMemoryUsage(const char* title, unsigned int allocatorDisplayOffset = 0) = 0;
|
|
||||||
|
|
||||||
virtual size_t DefragmentTick(size_t maxMoves, size_t maxAmount, bool bForce = false) = 0;
|
|
||||||
|
|
||||||
virtual UINT_PTR UsableSize(Hdl hdl) = 0;
|
|
||||||
|
|
||||||
// Pin the chunk until the next defrag tick, when it will be automatically unpinned
|
|
||||||
virtual UINT_PTR WeakPin(Hdl hdl) = 0;
|
|
||||||
|
|
||||||
// Pin the chunk until Unpin is called
|
|
||||||
virtual UINT_PTR Pin(Hdl hdl) = 0;
|
|
||||||
|
|
||||||
virtual void Unpin(Hdl hdl) = 0;
|
|
||||||
|
|
||||||
virtual const char* GetSourceOf(Hdl hdl) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
|
|
||||||
#ifndef _RELEASE
|
|
||||||
virtual void DumpState(const char* filename) = 0;
|
|
||||||
virtual void RestoreState(const char* filename) = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual ~IDefragAllocator() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_IDEFRAGALLOCATOR_H
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_IFILECHANGEMONITOR_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_IFILECHANGEMONITOR_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
struct IFileChangeListener
|
|
||||||
{
|
|
||||||
enum EChangeType
|
|
||||||
{
|
|
||||||
//! error or unknown change type
|
|
||||||
eChangeType_Unknown,
|
|
||||||
//! the file was created
|
|
||||||
eChangeType_Created,
|
|
||||||
//! the file was deleted
|
|
||||||
eChangeType_Deleted,
|
|
||||||
//! the file was modified (size changed,write)
|
|
||||||
eChangeType_Modified,
|
|
||||||
//! this is the old name of a renamed file
|
|
||||||
eChangeType_RenamedOldName,
|
|
||||||
//! this is the new name of a renamed file
|
|
||||||
eChangeType_RenamedNewName
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~IFileChangeListener() = default;
|
|
||||||
|
|
||||||
virtual void OnFileChange(const char* sFilename, EChangeType eType) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IFileChangeMonitor
|
|
||||||
{
|
|
||||||
virtual ~IFileChangeMonitor() = default;
|
|
||||||
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
// Register the path of a file or directory to monitor
|
|
||||||
// Path is relative to game directory, e.g. "Libs/WoundSystem/" or "Libs/WoundSystem/HitLocations.xml"
|
|
||||||
virtual bool RegisterListener(IFileChangeListener* pListener, const char* sMonitorItem) = 0;
|
|
||||||
// This function can be used to monitor files of specific type, e.g.
|
|
||||||
// RegisterListener(pListener, "Animations", "caf")
|
|
||||||
virtual bool RegisterListener(IFileChangeListener* pListener, const char* sFolder, const char* sExtension) = 0;
|
|
||||||
virtual bool UnregisterListener(IFileChangeListener* pListener) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_IFILECHANGEMONITOR_H
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : IOverloadSceneManager interface declaration.
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_IOVERLOADSCENEMANAGER_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_IOVERLOADSCENEMANAGER_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
// Name: COverloadSceneManager
|
|
||||||
// Desc: Manages overload values (eg CPU,GPU etc)
|
|
||||||
// 1.0="everything is ok" 0.0="very bad frame rate"
|
|
||||||
// various systems can use this information and control what is currently in the scene
|
|
||||||
// Author: James Chilvers
|
|
||||||
//==================================================================================================
|
|
||||||
struct IOverloadSceneManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual ~IOverloadSceneManager() {}
|
|
||||||
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
virtual void Update() = 0;
|
|
||||||
|
|
||||||
// Override auto-calculated scale to reach targetfps.
|
|
||||||
// frameScale is clamped to internal min/max values,
|
|
||||||
// dt is the length of time in seconds to transition
|
|
||||||
virtual void OverrideScale(float frameScale, float dt) = 0;
|
|
||||||
|
|
||||||
// Go back to auto-calculated scale from an overridden scale
|
|
||||||
virtual void ResetScale(float dt) = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};//------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_IOVERLOADSCENEMANAGER_H
|
|
||||||
@ -1,145 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Interface to the Performance HUD
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_IPERFHUD_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_IPERFHUD_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include <CryExtension/ICryUnknown.h>
|
|
||||||
#include <CryExtension/Impl/ClassWeaver.h>
|
|
||||||
#include <ICryMiniGUI.h>
|
|
||||||
#include <IXml.h>
|
|
||||||
|
|
||||||
struct ICryPerfHUDWidget
|
|
||||||
: public _reference_target_t
|
|
||||||
{
|
|
||||||
//
|
|
||||||
enum EWidgetID
|
|
||||||
{
|
|
||||||
eWidget_Warnings = 0,
|
|
||||||
eWidget_RenderStats,
|
|
||||||
eWidget_StreamingStats,
|
|
||||||
eWidget_RenderBatchStats,
|
|
||||||
eWidget_FpsBuckets,
|
|
||||||
eWidget_Particles,
|
|
||||||
eWidget_PakFile,
|
|
||||||
eWidget_Num, //number of widgets
|
|
||||||
};
|
|
||||||
|
|
||||||
ICryPerfHUDWidget(int id = -1)
|
|
||||||
: m_id(id)
|
|
||||||
{}
|
|
||||||
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
virtual ~ICryPerfHUDWidget() {}
|
|
||||||
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
virtual void Update() = 0;
|
|
||||||
virtual bool ShouldUpdate() = 0;
|
|
||||||
virtual void LoadBudgets(XmlNodeRef perfXML) = 0;
|
|
||||||
virtual void SaveStats(XmlNodeRef statsXML) = 0;
|
|
||||||
virtual void Enable(int mode) = 0;
|
|
||||||
virtual void Disable() = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
|
|
||||||
int m_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Base Interface for all engine module extensions
|
|
||||||
struct ICryPerfHUD
|
|
||||||
: public ICryUnknown
|
|
||||||
{
|
|
||||||
CRYINTERFACE_DECLARE(ICryPerfHUD, 0x268d142e043d464c, 0xa0776580f81b988a);
|
|
||||||
|
|
||||||
struct PerfBucket
|
|
||||||
{
|
|
||||||
ILINE PerfBucket(float _target)
|
|
||||||
{
|
|
||||||
target = _target;
|
|
||||||
timeAtTarget = 0.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float target;
|
|
||||||
float timeAtTarget;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum EHudState
|
|
||||||
{
|
|
||||||
eHudOff = 0,
|
|
||||||
eHudInFocus,
|
|
||||||
eHudOutOfFocus,
|
|
||||||
eHudNumStates,
|
|
||||||
};
|
|
||||||
|
|
||||||
// <interfuscator:shuffle>
|
|
||||||
// Called once to initialize HUD.
|
|
||||||
virtual void Init() = 0;
|
|
||||||
virtual void Done() = 0;
|
|
||||||
virtual void Draw() = 0;
|
|
||||||
virtual void LoadBudgets() = 0;
|
|
||||||
virtual void SaveStats(const char* filename = NULL) = 0;
|
|
||||||
virtual void ResetWidgets() = 0;
|
|
||||||
virtual void SetState(EHudState state) = 0;
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
virtual void Destroy() = 0;
|
|
||||||
|
|
||||||
// Retrieve name of the extension module.
|
|
||||||
virtual void Show(bool bRestoreState) = 0;
|
|
||||||
|
|
||||||
virtual void AddWidget(ICryPerfHUDWidget* pWidget) = 0;
|
|
||||||
virtual void RemoveWidget(ICryPerfHUDWidget* pWidget) = 0;
|
|
||||||
|
|
||||||
virtual minigui::IMiniCtrl* CreateMenu(const char* name, minigui::IMiniCtrl* pParent = NULL) = 0;
|
|
||||||
virtual bool CreateCVarMenuItem(minigui::IMiniCtrl* pMenu, const char* name, const char* controlVar, float controlVarOn, float controlVarOff) = 0;
|
|
||||||
virtual bool CreateCallbackMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::ClickCallback clickCallback, void* pCallbackData) = 0;
|
|
||||||
virtual minigui::IMiniInfoBox* CreateInfoMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::RenderCallback renderCallback, const minigui::Rect& rect, bool onAtStart = false) = 0;
|
|
||||||
virtual minigui::IMiniTable* CreateTableMenuItem(minigui::IMiniCtrl* pMenu, const char* name) = 0;
|
|
||||||
|
|
||||||
virtual minigui::IMiniCtrl* GetMenu(const char* name) = 0;
|
|
||||||
|
|
||||||
virtual void EnableWidget(ICryPerfHUDWidget::EWidgetID id, int mode) = 0;
|
|
||||||
virtual void DisableWidget(ICryPerfHUDWidget::EWidgetID id) = 0;
|
|
||||||
|
|
||||||
//Warnings - Widget Specific interface
|
|
||||||
virtual void AddWarning(float duration, const char* fmt, va_list argList) = 0;
|
|
||||||
virtual bool WarningsWindowEnabled() const = 0;
|
|
||||||
|
|
||||||
//FPS - Widget Specific interface
|
|
||||||
virtual const std::vector<PerfBucket>* GetFpsBuckets(float& totalTime) const = 0;
|
|
||||||
// </interfuscator:shuffle>
|
|
||||||
};
|
|
||||||
|
|
||||||
DECLARE_SMART_POINTERS(ICryPerfHUD);
|
|
||||||
|
|
||||||
void CryPerfHUDWarning(float duration, const char*, ...) PRINTF_PARAMS(2, 3);
|
|
||||||
inline void CryPerfHUDWarning(float duration, const char* format, ...)
|
|
||||||
{
|
|
||||||
if (gEnv && gEnv->pSystem)
|
|
||||||
{
|
|
||||||
ICryPerfHUD* pPerfHud = gEnv->pSystem->GetPerfHUD();
|
|
||||||
|
|
||||||
if (pPerfHud)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
pPerfHud->AddWarning(duration, format, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_IPERFHUD_H
|
|
||||||
@ -1,373 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <AzCore/Serialization/SerializeContext.h>
|
|
||||||
#include <AzCore/Serialization/EditContext.h>
|
|
||||||
#include <AzFramework/API/ApplicationAPI.h>
|
|
||||||
|
|
||||||
#include "LoadScreenComponent.h"
|
|
||||||
#include <IConsole.h>
|
|
||||||
|
|
||||||
#if AZ_LOADSCREENCOMPONENT_ENABLED
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// Due to issues with DLLs sometimes there can be different values of gEnv in different DLLs.
|
|
||||||
// So we use this preferred method of getting the global environment
|
|
||||||
SSystemGlobalEnvironment* GetGlobalEnv()
|
|
||||||
{
|
|
||||||
if (!GetISystem())
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetISystem()->GetGlobalEnvironment();
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* const s_gameFixedFpsCvarName = "game_load_screen_sequence_fixed_fps";
|
|
||||||
static const char* const s_gameMaxFpsCvarName = "game_load_screen_max_fps";
|
|
||||||
static const char* const s_gameMinimumLoadTimeCvarName = "game_load_screen_minimum_time";
|
|
||||||
|
|
||||||
static const char* const s_levelFixedFpsCvarName = "level_load_screen_sequence_fixed_fps";
|
|
||||||
static const char* const s_levelMaxFpsCvarName = "level_load_screen_max_fps";
|
|
||||||
static const char* const s_levelMinimumLoadTimeCvarName = "level_load_screen_minimum_time";
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Reflect(AZ::ReflectContext* context)
|
|
||||||
{
|
|
||||||
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
|
||||||
|
|
||||||
if (serializeContext)
|
|
||||||
{
|
|
||||||
serializeContext->Class<LoadScreenComponent, AZ::Component>()
|
|
||||||
->Version(1)
|
|
||||||
;
|
|
||||||
|
|
||||||
AZ::EditContext* editContext = serializeContext->GetEditContext();
|
|
||||||
if (editContext)
|
|
||||||
{
|
|
||||||
editContext->Class<LoadScreenComponent>(
|
|
||||||
"Load screen manager", "Allows management of a load screen")
|
|
||||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
|
||||||
->Attribute(AZ::Edit::Attributes::Category, "Game")
|
|
||||||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
|
||||||
{
|
|
||||||
provided.push_back(AZ_CRC("LoadScreenService", 0x901b031c));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
|
||||||
{
|
|
||||||
incompatible.push_back(AZ_CRC("LoadScreenService", 0x901b031c));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Reset()
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::None;
|
|
||||||
|
|
||||||
m_fixedDeltaTimeInSeconds = -1.0f;
|
|
||||||
m_maxDeltaTimeInSeconds = -1.0f;
|
|
||||||
m_previousCallTimeForUpdateAndRender = CTimeValue();
|
|
||||||
m_processingLoadScreen.store(false);
|
|
||||||
|
|
||||||
// Reset CVars so they're not carried over to other levels
|
|
||||||
SSystemGlobalEnvironment* pGEnv = GetGlobalEnv();
|
|
||||||
if (pGEnv && pGEnv->pConsole)
|
|
||||||
{
|
|
||||||
if (ICVar* var = pGEnv->pConsole->GetCVar(s_levelFixedFpsCvarName))
|
|
||||||
{
|
|
||||||
var->Set("");
|
|
||||||
}
|
|
||||||
if (ICVar* var = pGEnv->pConsole->GetCVar(s_levelMaxFpsCvarName))
|
|
||||||
{
|
|
||||||
var->Set("");
|
|
||||||
}
|
|
||||||
if (ICVar* var = pGEnv->pConsole->GetCVar(s_levelMinimumLoadTimeCvarName))
|
|
||||||
{
|
|
||||||
var->Set("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::LoadConfigSettings(const char* fixedFpsVarName, const char* maxFpsVarName, const char* minimumLoadTimeVarName)
|
|
||||||
{
|
|
||||||
m_fixedDeltaTimeInSeconds = -1.0f;
|
|
||||||
m_maxDeltaTimeInSeconds = -1.0f;
|
|
||||||
m_minimumLoadTimeInSeconds = 0.0f;
|
|
||||||
|
|
||||||
SSystemGlobalEnvironment* pGEnv = GetGlobalEnv();
|
|
||||||
if (pGEnv && pGEnv->pConsole)
|
|
||||||
{
|
|
||||||
ICVar* fixedFpsVar = pGEnv->pConsole->GetCVar(fixedFpsVarName);
|
|
||||||
if (fixedFpsVar && fixedFpsVar->GetFVal() > 0.0f)
|
|
||||||
{
|
|
||||||
m_fixedDeltaTimeInSeconds = (1.0f / fixedFpsVar->GetFVal());
|
|
||||||
}
|
|
||||||
|
|
||||||
ICVar* maxFpsVar = pGEnv->pConsole->GetCVar(maxFpsVarName);
|
|
||||||
if (maxFpsVar && maxFpsVar->GetFVal() > 0.0f)
|
|
||||||
{
|
|
||||||
m_maxDeltaTimeInSeconds = (1.0f / maxFpsVar->GetFVal());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ICVar* minimumLoadTimeVar = pGEnv->pConsole->GetCVar(minimumLoadTimeVarName))
|
|
||||||
{
|
|
||||||
// Never allow values below 0 seconds
|
|
||||||
m_minimumLoadTimeInSeconds = AZStd::max<float>(minimumLoadTimeVar->GetFVal(), 0.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Init()
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Activate()
|
|
||||||
{
|
|
||||||
CrySystemEventBus::Handler::BusConnect();
|
|
||||||
LoadScreenBus::Handler::BusConnect(GetEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Deactivate()
|
|
||||||
{
|
|
||||||
CrySystemEventBus::Handler::BusDisconnect();
|
|
||||||
LoadScreenBus::Handler::BusDisconnect(GetEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::OnCrySystemInitialized(ISystem& system, const SSystemInitParams&)
|
|
||||||
{
|
|
||||||
SSystemGlobalEnvironment* pGEnv = system.GetGlobalEnvironment();
|
|
||||||
|
|
||||||
// Can't use macros here because we have to use our pointer.
|
|
||||||
if (pGEnv && pGEnv->pConsole)
|
|
||||||
{
|
|
||||||
pGEnv->pConsole->Register("ly_EnableLoadingThread", &m_loadingThreadEnabled, 0, VF_NULL,
|
|
||||||
"EXPERIMENTAL. Enable fully threaded loading where the LoadingScreen is drawn on a thread that isn't loading data.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pGEnv && !pGEnv->IsEditor())
|
|
||||||
{
|
|
||||||
// If not running from the editor, then run GameStart
|
|
||||||
GameStart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::OnCrySystemShutdown(ISystem&)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::UpdateAndRender()
|
|
||||||
{
|
|
||||||
SSystemGlobalEnvironment* pGEnv = GetGlobalEnv();
|
|
||||||
|
|
||||||
if (m_loadScreenState == LoadScreenState::Showing && pGEnv && pGEnv->pTimer)
|
|
||||||
{
|
|
||||||
AZ_Assert(GetCurrentThreadId() == pGEnv->mMainThreadId, "UpdateAndRender should only be called from the main thread");
|
|
||||||
|
|
||||||
// Throttling.
|
|
||||||
if (!m_previousCallTimeForUpdateAndRender.GetValue())
|
|
||||||
{
|
|
||||||
// This is the first call to UpdateAndRender().
|
|
||||||
m_previousCallTimeForUpdateAndRender = pGEnv->pTimer->GetAsyncTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
const CTimeValue callTimeForUpdateAndRender = pGEnv->pTimer->GetAsyncTime();
|
|
||||||
const float deltaTimeInSeconds = fabs((callTimeForUpdateAndRender - m_previousCallTimeForUpdateAndRender).GetSeconds());
|
|
||||||
|
|
||||||
// Early-out: We DON'T need to execute UpdateAndRender() at a higher frequency than 30 FPS.
|
|
||||||
const bool shouldThrottle = m_maxDeltaTimeInSeconds > 0.0f && deltaTimeInSeconds < m_maxDeltaTimeInSeconds;
|
|
||||||
|
|
||||||
if (!shouldThrottle)
|
|
||||||
{
|
|
||||||
bool expectedValue = false;
|
|
||||||
if (m_processingLoadScreen.compare_exchange_strong(expectedValue, true))
|
|
||||||
{
|
|
||||||
m_previousCallTimeForUpdateAndRender = callTimeForUpdateAndRender;
|
|
||||||
|
|
||||||
const float updateDeltaTime = (m_fixedDeltaTimeInSeconds == -1.0f) ? deltaTimeInSeconds : m_fixedDeltaTimeInSeconds;
|
|
||||||
|
|
||||||
EBUS_EVENT(LoadScreenUpdateNotificationBus, UpdateAndRender, updateDeltaTime);
|
|
||||||
|
|
||||||
// Some platforms (iOS, OSX) require system events to be pumped in order to update the screen
|
|
||||||
AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::PumpSystemEventLoopUntilEmpty);
|
|
||||||
|
|
||||||
m_processingLoadScreen.store(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::GameStart()
|
|
||||||
{
|
|
||||||
if (m_loadScreenState == LoadScreenState::None)
|
|
||||||
{
|
|
||||||
LoadConfigSettings(s_gameFixedFpsCvarName, s_gameMaxFpsCvarName, s_gameMinimumLoadTimeCvarName);
|
|
||||||
|
|
||||||
const bool usingLoadingThread = IsLoadingThreadEnabled();
|
|
||||||
|
|
||||||
AZ::EBusLogicalResult<bool, AZStd::logical_or<bool>> anyHandled(false);
|
|
||||||
EBUS_EVENT_RESULT(anyHandled, LoadScreenNotificationBus, NotifyGameLoadStart, usingLoadingThread);
|
|
||||||
|
|
||||||
if (anyHandled.value)
|
|
||||||
{
|
|
||||||
if (usingLoadingThread)
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::ShowingMultiThreaded;
|
|
||||||
|
|
||||||
GetGlobalEnv()->pRenderer->StartLoadtimePlayback(this);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::Showing;
|
|
||||||
|
|
||||||
// Kick-start the first frame.
|
|
||||||
UpdateAndRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ITimer* timer = GetGlobalEnv()->pTimer)
|
|
||||||
{
|
|
||||||
m_lastStartTime = timer->GetAsyncTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::LevelStart()
|
|
||||||
{
|
|
||||||
if (m_loadScreenState == LoadScreenState::None)
|
|
||||||
{
|
|
||||||
LoadConfigSettings(s_levelFixedFpsCvarName, s_levelMaxFpsCvarName, s_levelMinimumLoadTimeCvarName);
|
|
||||||
|
|
||||||
const bool usingLoadingThread = IsLoadingThreadEnabled();
|
|
||||||
|
|
||||||
AZ::EBusLogicalResult<bool, AZStd::logical_or<bool>> anyHandled(false);
|
|
||||||
EBUS_EVENT_RESULT(anyHandled, LoadScreenNotificationBus, NotifyLevelLoadStart, usingLoadingThread);
|
|
||||||
|
|
||||||
if (anyHandled.value)
|
|
||||||
{
|
|
||||||
if (usingLoadingThread)
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::ShowingMultiThreaded;
|
|
||||||
|
|
||||||
GetGlobalEnv()->pRenderer->StartLoadtimePlayback(this);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::Showing;
|
|
||||||
|
|
||||||
// Kick-start the first frame.
|
|
||||||
UpdateAndRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ITimer* timer = GetGlobalEnv()->pTimer)
|
|
||||||
{
|
|
||||||
m_lastStartTime = timer->GetAsyncTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Pause()
|
|
||||||
{
|
|
||||||
if (m_loadScreenState == LoadScreenState::Showing)
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::Paused;
|
|
||||||
}
|
|
||||||
else if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded)
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::PausedMultithreaded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Resume()
|
|
||||||
{
|
|
||||||
if (m_loadScreenState == LoadScreenState::Paused)
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::Showing;
|
|
||||||
}
|
|
||||||
else if (m_loadScreenState == LoadScreenState::PausedMultithreaded)
|
|
||||||
{
|
|
||||||
m_loadScreenState = LoadScreenState::ShowingMultiThreaded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::Stop()
|
|
||||||
{
|
|
||||||
// If we were actually in a load screen, check if we need to wait longer.
|
|
||||||
if (m_loadScreenState != LoadScreenState::None && m_minimumLoadTimeInSeconds > 0.0f)
|
|
||||||
{
|
|
||||||
if (ITimer* timer = GetGlobalEnv()->pTimer)
|
|
||||||
{
|
|
||||||
CTimeValue currentTime = timer->GetAsyncTime();
|
|
||||||
float timeSinceStart = currentTime.GetDifferenceInSeconds(m_lastStartTime);
|
|
||||||
|
|
||||||
while (timeSinceStart < m_minimumLoadTimeInSeconds)
|
|
||||||
{
|
|
||||||
// Simple loop that makes sure the loading screens update but also doesn't consume the whole core.
|
|
||||||
|
|
||||||
if (m_loadScreenState == LoadScreenState::Showing)
|
|
||||||
{
|
|
||||||
EBUS_EVENT(LoadScreenBus, UpdateAndRender);
|
|
||||||
}
|
|
||||||
|
|
||||||
CrySleep(0);
|
|
||||||
|
|
||||||
currentTime = timer->GetAsyncTime();
|
|
||||||
timeSinceStart = currentTime.GetDifferenceInSeconds(m_lastStartTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded)
|
|
||||||
{
|
|
||||||
// This will block until the other thread completes.
|
|
||||||
GetGlobalEnv()->pRenderer->StopLoadtimePlayback();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_loadScreenState != LoadScreenState::None)
|
|
||||||
{
|
|
||||||
EBUS_EVENT(LoadScreenNotificationBus, NotifyLoadEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
Reset();
|
|
||||||
|
|
||||||
m_loadScreenState = LoadScreenState::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LoadScreenComponent::IsPlaying()
|
|
||||||
{
|
|
||||||
return m_loadScreenState != LoadScreenState::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::LoadtimeUpdate(float deltaTime)
|
|
||||||
{
|
|
||||||
if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded)
|
|
||||||
{
|
|
||||||
EBUS_EVENT(LoadScreenUpdateNotificationBus, LoadThreadUpdate, deltaTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadScreenComponent::LoadtimeRender()
|
|
||||||
{
|
|
||||||
if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded)
|
|
||||||
{
|
|
||||||
EBUS_EVENT(LoadScreenUpdateNotificationBus, LoadThreadRender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // if AZ_LOADSCREENCOMPONENT_ENABLED
|
|
||||||
@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <AzCore/Component/Component.h>
|
|
||||||
#include <AzCore/Component/EntityId.h>
|
|
||||||
#include <AzCore/std/parallel/atomic.h>
|
|
||||||
|
|
||||||
#include <CrySystemBus.h>
|
|
||||||
#include <LoadScreenBus.h>
|
|
||||||
#include <IRenderer.h>
|
|
||||||
|
|
||||||
#if AZ_LOADSCREENCOMPONENT_ENABLED
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This component is responsible for managing the load screen.
|
|
||||||
*/
|
|
||||||
class LoadScreenComponent
|
|
||||||
: public AZ::Component
|
|
||||||
, public CrySystemEventBus::Handler
|
|
||||||
, public LoadScreenBus::Handler
|
|
||||||
, public ILoadtimeCallback
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AZ_COMPONENT(LoadScreenComponent, "{97CDBD6C-C621-4427-87C8-10E1B8F947FF}");
|
|
||||||
|
|
||||||
LoadScreenComponent() = default;
|
|
||||||
~LoadScreenComponent() = default;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// AZ::Component interface implementation
|
|
||||||
void Init() override;
|
|
||||||
void Activate() override;
|
|
||||||
void Deactivate() override;
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
||||||
// CrySystemEvents
|
|
||||||
void OnCrySystemInitialized(ISystem&, const SSystemInitParams& params) override;
|
|
||||||
void OnCrySystemShutdown(ISystem&) override;
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// LoadScreenBus interface implementation
|
|
||||||
void UpdateAndRender() override;
|
|
||||||
void GameStart() override;
|
|
||||||
void LevelStart() override;
|
|
||||||
void Pause() override;
|
|
||||||
void Resume() override;
|
|
||||||
void Stop() override;
|
|
||||||
bool IsPlaying() override;
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// ILoadtimeCallback interface implementation
|
|
||||||
void LoadtimeUpdate(float deltaTime) override;
|
|
||||||
void LoadtimeRender() override;
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
inline bool IsLoadingThreadEnabled() const
|
|
||||||
{
|
|
||||||
return m_loadingThreadEnabled != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static void Reflect(AZ::ReflectContext* context);
|
|
||||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
|
||||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void Reset();
|
|
||||||
void LoadConfigSettings(const char* fixedFpsVarName, const char* maxFpsVarName, const char* minimumLoadTimeVarName);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
enum class LoadScreenState
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Showing,
|
|
||||||
ShowingMultiThreaded,
|
|
||||||
Paused,
|
|
||||||
PausedMultithreaded,
|
|
||||||
};
|
|
||||||
LoadScreenState m_loadScreenState{ LoadScreenState::None };
|
|
||||||
|
|
||||||
float m_fixedDeltaTimeInSeconds{ -1.0f };
|
|
||||||
float m_maxDeltaTimeInSeconds{ -1.0f };
|
|
||||||
float m_minimumLoadTimeInSeconds{ 0.0f };
|
|
||||||
|
|
||||||
CTimeValue m_lastStartTime;
|
|
||||||
CTimeValue m_previousCallTimeForUpdateAndRender;
|
|
||||||
AZStd::atomic_bool m_processingLoadScreen{ false };
|
|
||||||
|
|
||||||
int32_t m_loadingThreadEnabled{ 0 };
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // if AZ_LOADSCREENCOMPONENT_ENABLED
|
|
||||||
@ -1,321 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_RENDELEMENT_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_RENDELEMENT_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
//=============================================================
|
|
||||||
|
|
||||||
#include "VertexFormats.h"
|
|
||||||
|
|
||||||
class CRendElementBase;
|
|
||||||
struct CRenderChunk;
|
|
||||||
struct PrimitiveGroup;
|
|
||||||
class CShader;
|
|
||||||
struct SShaderTechnique;
|
|
||||||
class CParserBin;
|
|
||||||
struct SParserFrame;
|
|
||||||
|
|
||||||
namespace AZ
|
|
||||||
{
|
|
||||||
namespace Vertex
|
|
||||||
{
|
|
||||||
class Format;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum EDataType
|
|
||||||
{
|
|
||||||
eDATA_Unknown = 0,
|
|
||||||
eDATA_Sky,
|
|
||||||
eDATA_Beam,
|
|
||||||
eDATA_ClientPoly,
|
|
||||||
eDATA_Flare,
|
|
||||||
eDATA_Terrain,
|
|
||||||
eDATA_SkyZone,
|
|
||||||
eDATA_Mesh,
|
|
||||||
eDATA_Imposter,
|
|
||||||
eDATA_LensOptics,
|
|
||||||
eDATA_FarTreeSprites_Deprecated,
|
|
||||||
eDATA_OcclusionQuery,
|
|
||||||
eDATA_Particle,
|
|
||||||
eDATA_GPUParticle,
|
|
||||||
eDATA_PostProcess,
|
|
||||||
eDATA_HDRProcess,
|
|
||||||
eDATA_Cloud,
|
|
||||||
eDATA_HDRSky,
|
|
||||||
eDATA_FogVolume,
|
|
||||||
eDATA_WaterVolume,
|
|
||||||
eDATA_WaterOcean,
|
|
||||||
eDATA_VolumeObject,
|
|
||||||
eDATA_PrismObject, // normally this would be #if !defined(EXCLUDE_DOCUMENTATION_PURPOSE) but we keep it to get consistent numbers for serialization
|
|
||||||
eDATA_DeferredShading,
|
|
||||||
eDATA_GameEffect,
|
|
||||||
eDATA_BreakableGlass,
|
|
||||||
eDATA_GeomCache,
|
|
||||||
eDATA_Gem,
|
|
||||||
};
|
|
||||||
|
|
||||||
#include <Cry_Color.h>
|
|
||||||
|
|
||||||
//=======================================================
|
|
||||||
|
|
||||||
#define FCEF_TRANSFORM 1
|
|
||||||
#define FCEF_DIRTY 2
|
|
||||||
#define FCEF_NODEL 4
|
|
||||||
#define FCEF_DELETED 8
|
|
||||||
|
|
||||||
#define FCEF_MODIF_TC 0x10
|
|
||||||
#define FCEF_MODIF_VERT 0x20
|
|
||||||
#define FCEF_MODIF_COL 0x40
|
|
||||||
#define FCEF_MODIF_MASK 0xf0
|
|
||||||
|
|
||||||
#define FCEF_UPDATEALWAYS 0x100
|
|
||||||
#define FCEF_ALLOC_CUST_FLOAT_DATA 0x200
|
|
||||||
#define FCEF_MERGABLE 0x400
|
|
||||||
|
|
||||||
#define FCEF_SKINNED 0x800
|
|
||||||
#define FCEF_PRE_DRAW_DONE 0x1000
|
|
||||||
|
|
||||||
#define FGP_NOCALC 1
|
|
||||||
#define FGP_SRC 2
|
|
||||||
#define FGP_REAL 4
|
|
||||||
#define FGP_WAIT 8
|
|
||||||
|
|
||||||
#define FGP_STAGE_SHIFT 0x10
|
|
||||||
|
|
||||||
#define MAX_CUSTOM_TEX_BINDS_NUM 2
|
|
||||||
|
|
||||||
struct SGeometryInfo;
|
|
||||||
class CRendElement;
|
|
||||||
|
|
||||||
struct IRenderElementDelegate
|
|
||||||
{
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow) = 0;
|
|
||||||
virtual bool mfDraw(CShader* shader, SShaderPass* pass) = 0;
|
|
||||||
virtual bool mfSetSampler([[maybe_unused]] int customId, [[maybe_unused]] int nTUnit, [[maybe_unused]] int nTState, [[maybe_unused]] int nTexMaterialSlot, [[maybe_unused]] int nSUnit) { return true; };
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IRenderElement
|
|
||||||
{
|
|
||||||
virtual int mfGetMatId() = 0;
|
|
||||||
virtual uint16 mfGetFlags() = 0;
|
|
||||||
virtual void mfSetFlags(uint16 fl) = 0;
|
|
||||||
virtual void mfUpdateFlags(uint16 fl) = 0;
|
|
||||||
virtual void mfClearFlags(uint16 fl) = 0;
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow) = 0;
|
|
||||||
virtual void mfCenter(Vec3& centr, CRenderObject* pObj) = 0;
|
|
||||||
virtual void mfGetBBox(Vec3& vMins, Vec3& vMaxs) = 0;
|
|
||||||
virtual void mfReset() = 0;
|
|
||||||
virtual void mfGetPlane(Plane_tpl<f32>& pl) = 0;
|
|
||||||
virtual void mfExport(struct SShaderSerializeContext& SC) = 0;
|
|
||||||
virtual void mfImport(struct SShaderSerializeContext& SC, uint32& offset) = 0;
|
|
||||||
virtual void mfPrecache(const SShaderItem& SH) = 0;
|
|
||||||
virtual bool mfIsHWSkinned() = 0;
|
|
||||||
virtual bool mfCheckUpdate(int Flags, uint16 nFrame, bool bTessellation = false) = 0;
|
|
||||||
virtual bool mfUpdate(int Flags, bool bTessellation = false) = 0;
|
|
||||||
virtual bool mfCompile(CParserBin& Parser, SParserFrame& Frame) = 0;
|
|
||||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm) = 0;
|
|
||||||
virtual bool mfPreDraw(SShaderPass* sl) = 0;
|
|
||||||
virtual bool mfSetSampler(int customId, int nTUnit, int nTState, int nTexMaterialSlot, int nSUnit) = 0;
|
|
||||||
virtual void mfSetDelegate(IRenderElementDelegate* pDelegate) = 0;
|
|
||||||
virtual IRenderElementDelegate* mfGetDelegate() = 0;
|
|
||||||
virtual CRenderChunk* mfGetMatInfo() = 0;
|
|
||||||
virtual TRenderChunkArray* mfGetMatInfoList() = 0;
|
|
||||||
virtual void* mfGetPointer(ESrcPointer ePT, int* Stride, EParamType Type, ESrcPointer Dst, int Flags) = 0;
|
|
||||||
virtual AZ::Vertex::Format GetVertexFormat() const = 0;
|
|
||||||
virtual void* GetCustomData() const = 0;
|
|
||||||
virtual int GetCustomTexBind(int i) const = 0;
|
|
||||||
virtual CRendElementBase* mfCopyConstruct() = 0;
|
|
||||||
virtual EDataType mfGetType() = 0;
|
|
||||||
virtual int Size() = 0;
|
|
||||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class CRendElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static CRendElement m_RootGlobal;
|
|
||||||
static CRendElement m_RootRelease[];
|
|
||||||
CRendElement* m_NextGlobal;
|
|
||||||
CRendElement* m_PrevGlobal;
|
|
||||||
|
|
||||||
EDataType m_Type;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void UnlinkGlobal()
|
|
||||||
{
|
|
||||||
if (!m_NextGlobal || !m_PrevGlobal)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_NextGlobal->m_PrevGlobal = m_PrevGlobal;
|
|
||||||
m_PrevGlobal->m_NextGlobal = m_NextGlobal;
|
|
||||||
m_NextGlobal = m_PrevGlobal = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void LinkGlobal(CRendElement* Before)
|
|
||||||
{
|
|
||||||
if (m_NextGlobal || m_PrevGlobal)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_NextGlobal = Before->m_NextGlobal;
|
|
||||||
Before->m_NextGlobal->m_PrevGlobal = this;
|
|
||||||
Before->m_NextGlobal = this;
|
|
||||||
m_PrevGlobal = Before;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
CRendElement();
|
|
||||||
virtual ~CRendElement();
|
|
||||||
virtual void Release(bool bForce = false);
|
|
||||||
virtual const char* mfTypeString();
|
|
||||||
virtual void mfSetType(EDataType t) { m_Type = t; }
|
|
||||||
virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {}
|
|
||||||
virtual int Size() { return 0; }
|
|
||||||
|
|
||||||
static void ShutDown();
|
|
||||||
static void Tick();
|
|
||||||
static void Cleanup();
|
|
||||||
};
|
|
||||||
|
|
||||||
class CRendElementBase
|
|
||||||
: public CRendElement
|
|
||||||
, public IRenderElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
uint16 m_Flags;
|
|
||||||
uint16 m_nFrameUpdated;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void* m_CustomData;
|
|
||||||
int m_CustomTexBind[MAX_CUSTOM_TEX_BINDS_NUM];
|
|
||||||
|
|
||||||
struct SGeometryStreamInfo
|
|
||||||
{
|
|
||||||
const void* pStream;
|
|
||||||
int nOffset;
|
|
||||||
int nStride;
|
|
||||||
};
|
|
||||||
struct SGeometryInfo
|
|
||||||
{
|
|
||||||
uint32 bonesRemapGUID; // Input paremeter to fetch correct skinning stream.
|
|
||||||
|
|
||||||
int primitiveType; //!< \see eRenderPrimitiveType
|
|
||||||
AZ::Vertex::Format vertexFormat;
|
|
||||||
uint32 streamMask;
|
|
||||||
|
|
||||||
int32 nFirstIndex;
|
|
||||||
int32 nNumIndices;
|
|
||||||
uint32 nFirstVertex;
|
|
||||||
uint32 nNumVertices;
|
|
||||||
|
|
||||||
uint32 nMaxVertexStreams;
|
|
||||||
|
|
||||||
SGeometryStreamInfo indexStream;
|
|
||||||
SGeometryStreamInfo vertexStream[VSF_NUM];
|
|
||||||
|
|
||||||
void* pTessellationAdjacencyBuffer;
|
|
||||||
void* pSkinningExtraBonesBuffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
CRendElementBase();
|
|
||||||
virtual ~CRendElementBase();
|
|
||||||
|
|
||||||
|
|
||||||
virtual void mfPrepare(bool bCheckOverflow) override
|
|
||||||
{
|
|
||||||
if (m_delegate)
|
|
||||||
{
|
|
||||||
m_delegate->mfPrepare(bCheckOverflow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool mfDraw(CShader* ef, SShaderPass* sfm) override { return m_delegate ? m_delegate->mfDraw(ef, sfm) : true; }
|
|
||||||
bool mfSetSampler(int customId, int nTUnit, int nTState, int nTexMaterialSlot, int nSUnit) override { return m_delegate ? m_delegate->mfSetSampler(customId, nTUnit, nTState, nTexMaterialSlot, nSUnit) : false; }
|
|
||||||
void mfSetDelegate(IRenderElementDelegate* pDelegate) override { m_delegate = pDelegate; }
|
|
||||||
IRenderElementDelegate* mfGetDelegate() { return m_delegate; }
|
|
||||||
|
|
||||||
EDataType mfGetType() override { return m_Type; };
|
|
||||||
|
|
||||||
CRenderChunk* mfGetMatInfo() override { return nullptr; }
|
|
||||||
TRenderChunkArray* mfGetMatInfoList() override { return nullptr; }
|
|
||||||
int mfGetMatId() override { return -1; }
|
|
||||||
void mfReset() override {};
|
|
||||||
CRendElementBase* mfCopyConstruct() override;
|
|
||||||
void mfCenter(Vec3& centr, CRenderObject* pObj) override;
|
|
||||||
|
|
||||||
bool mfCompile([[maybe_unused]] CParserBin& Parser, [[maybe_unused]] SParserFrame& Frame) override { return false; }
|
|
||||||
bool mfPreDraw([[maybe_unused]] SShaderPass* sl) override { return true; }
|
|
||||||
bool mfUpdate([[maybe_unused]] int Flags, [[maybe_unused]] bool bTessellation = false) override { return true; }
|
|
||||||
void mfPrecache([[maybe_unused]] const SShaderItem& SH) override {}
|
|
||||||
void mfExport([[maybe_unused]] struct SShaderSerializeContext& SC) override { CryFatalError("mfExport has not been implemented for this render element type"); }
|
|
||||||
void mfImport([[maybe_unused]] struct SShaderSerializeContext& SC, [[maybe_unused]] uint32& offset) override { CryFatalError("mfImport has not been implemented for this render element type"); }
|
|
||||||
void mfGetPlane(Plane_tpl<f32>& pl) override;
|
|
||||||
void* mfGetPointer([[maybe_unused]] ESrcPointer ePT, [[maybe_unused]] int* Stride, [[maybe_unused]] EParamType Type, [[maybe_unused]] ESrcPointer Dst, [[maybe_unused]] int Flags) override { return nullptr; }
|
|
||||||
|
|
||||||
uint16 mfGetFlags() override { return m_Flags; }
|
|
||||||
void mfSetFlags(uint16 fl) override { m_Flags = fl; }
|
|
||||||
void mfUpdateFlags(uint16 fl) override { m_Flags |= fl; }
|
|
||||||
void mfClearFlags(uint16 fl) override { m_Flags &= ~fl; }
|
|
||||||
bool mfCheckUpdate(int Flags, uint16 nFrame, bool bTessellation = false) override
|
|
||||||
{
|
|
||||||
if (nFrame != m_nFrameUpdated || (m_Flags & (FCEF_DIRTY | FCEF_SKINNED | FCEF_UPDATEALWAYS)))
|
|
||||||
{
|
|
||||||
m_nFrameUpdated = nFrame;
|
|
||||||
return mfUpdate(Flags, bTessellation);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
void mfGetBBox(Vec3& vMins, Vec3& vMaxs) override
|
|
||||||
{
|
|
||||||
vMins.Set(0, 0, 0);
|
|
||||||
vMaxs.Set(0, 0, 0);
|
|
||||||
}
|
|
||||||
bool mfIsHWSkinned() override { return false; }
|
|
||||||
int Size() override { return 0; }
|
|
||||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const override {}
|
|
||||||
AZ::Vertex::Format GetVertexFormat() const override { return AZ::Vertex::Format(eVF_Unknown); };
|
|
||||||
virtual bool GetGeometryInfo([[maybe_unused]] SGeometryInfo& streams) { return false; }
|
|
||||||
void Draw([[maybe_unused]] CRenderObject* pObj, [[maybe_unused]] const struct SGraphicsPiplinePassContext& ctx) {};
|
|
||||||
void* GetCustomData() const { return m_CustomData; }
|
|
||||||
int GetCustomTexBind(int index) const { return m_CustomTexBind[index]; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
IRenderElementDelegate * m_delegate = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "CREMesh.h"
|
|
||||||
#include "CRESky.h"
|
|
||||||
#include "CREOcclusionQuery.h"
|
|
||||||
#include "CREImposter.h"
|
|
||||||
#include "CREBaseCloud.h"
|
|
||||||
#include "CREPostProcess.h"
|
|
||||||
#include "CREFogVolume.h"
|
|
||||||
#include "CREWaterVolume.h"
|
|
||||||
#include "CREWaterOcean.h"
|
|
||||||
#include "CREVolumeObject.h"
|
|
||||||
#include "CREGameEffect.h"
|
|
||||||
#include "CREGeomCache.h"
|
|
||||||
|
|
||||||
#if !defined(EXCLUDE_DOCUMENTATION_PURPOSE)
|
|
||||||
#include "CREPrismObject.h"
|
|
||||||
#endif // EXCLUDE_DOCUMENTATION_PURPOSE
|
|
||||||
|
|
||||||
//==========================================================
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_RENDELEMENT_H
|
|
||||||
@ -1,512 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYCOMMON_TYPELIBRARY_H
|
|
||||||
#define CRYINCLUDE_CRYCOMMON_TYPELIBRARY_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ISoftCodeMgr.h> // <> required for Interfuscator
|
|
||||||
|
|
||||||
#include <AzCore/std/containers/map.h>
|
|
||||||
#include <AzCore/std/string/string.h>
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
|
|
||||||
// Internal: Used by SC types to auto-remove themselves from their TypeRegistrar on destruction.
|
|
||||||
struct InstanceTracker
|
|
||||||
{
|
|
||||||
InstanceTracker()
|
|
||||||
: m_pRegistrar()
|
|
||||||
{}
|
|
||||||
|
|
||||||
~InstanceTracker()
|
|
||||||
{
|
|
||||||
if (m_pRegistrar)
|
|
||||||
{
|
|
||||||
m_pRegistrar->RemoveInstance(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetRegistrar(ITypeRegistrar* pRegistrar)
|
|
||||||
{
|
|
||||||
m_pRegistrar = pRegistrar;
|
|
||||||
}
|
|
||||||
|
|
||||||
ITypeRegistrar* m_pRegistrar; // Valid if created by a registrar, otherwise NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
|
|
||||||
// Include this for SEH support
|
|
||||||
#include <excpt.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
Used to declare the interface as having an associated TypeLibrary.
|
|
||||||
Usage:
|
|
||||||
struct IMyInterface
|
|
||||||
{
|
|
||||||
DECLARE_TYPELIB(IMyInterface);
|
|
||||||
*/
|
|
||||||
#define DECLARE_TYPELIB(IName) \
|
|
||||||
static void VisitMembers(IExchanger & ex) {} \
|
|
||||||
typedef CTypeLibrary<IName> TLibrary
|
|
||||||
|
|
||||||
/*
|
|
||||||
Exposes a class to a TypeLibrary for registration.
|
|
||||||
Usage:
|
|
||||||
class MyThing : public IThing
|
|
||||||
{
|
|
||||||
DECLARE_TYPE(MyThing, IThing);
|
|
||||||
...
|
|
||||||
*/
|
|
||||||
#define DECLARE_TYPE(TName, TSuperType) \
|
|
||||||
public: \
|
|
||||||
void VisitMembers(IExchanger & ex) { TSuperType::VisitMembers(ex); VisitMember<__START_MEMBERS>(ex); } \
|
|
||||||
private: \
|
|
||||||
friend class TypeRegistrar<TName>; \
|
|
||||||
static const size_t __START_MEMBERS = __COUNTER__ + 1; \
|
|
||||||
template <size_t IDX> \
|
|
||||||
void VisitMember(IExchanger & exchanger) {} \
|
|
||||||
InstanceTracker __instanceTracker
|
|
||||||
|
|
||||||
#ifdef SOFTCODE
|
|
||||||
#define _EXPORT_TYPE_LIB(Interface) \
|
|
||||||
extern "C" ITypeLibrary * GetTypeLibrary() { return CTypeLibrary<Interface>::Instance(); }
|
|
||||||
#else
|
|
||||||
#define _EXPORT_TYPE_LIB(Interface)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Internal: Outputs the specialized method template for the member at index
|
|
||||||
#define _SOFT_MEMBER_VISITOR(member, index) \
|
|
||||||
template <> \
|
|
||||||
void VisitMember<index>(IExchanger & ex) { ex.Visit(#member, member); VisitMember<index + 1>(ex); }
|
|
||||||
|
|
||||||
/*
|
|
||||||
Used to expose a class member to SoftCoding (to allow run-time member exchange)
|
|
||||||
If SoftCode is disabled this does nothing and simple emits the member.
|
|
||||||
For array types, use SOFT_ARRAY() instead or use AZStd::array which allows assignment.
|
|
||||||
Usage: std::vector<string> SOFT(m_myStrings);
|
|
||||||
*/
|
|
||||||
#define SOFT(member) \
|
|
||||||
member; \
|
|
||||||
_SOFT_MEMBER_VISITOR(member, __COUNTER__)
|
|
||||||
|
|
||||||
/*
|
|
||||||
Used to expose a primitive array type to SoftCoding.
|
|
||||||
Declare it directly after the member.
|
|
||||||
NOTE: It's cleaner to convert the member to AZStd::array as
|
|
||||||
this avoid having to use this special case while preserving semantics.
|
|
||||||
Usage:
|
|
||||||
ColorB m_colors[20];
|
|
||||||
SOFT_ARRAY(m_colors);
|
|
||||||
*/
|
|
||||||
#define SOFT_ARRAY(arrayMember) _SOFT_MEMBER_VISITOR(arrayMember, __COUNTER__)
|
|
||||||
|
|
||||||
// Internal: Executes given lambda in an SEH try block.
|
|
||||||
template <typename TLambda>
|
|
||||||
void SoftCodeTry(TLambda& lambda)
|
|
||||||
{
|
|
||||||
__try
|
|
||||||
{
|
|
||||||
lambda();
|
|
||||||
}
|
|
||||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal: Used by TypeRegistry. Use SOFTCODE_RETRY() for user code.
|
|
||||||
#define SOFTCODE_TRY(exp) SoftCodeTry([&](){ exp; })
|
|
||||||
#define SOFTCODE_TRY_BLOCK SoftCodeTry([&]() {
|
|
||||||
#define SOFTCODE_TRY_END });
|
|
||||||
|
|
||||||
/*
|
|
||||||
Internal: Attempt a given lambda functor. In the even on an exception execution will pause
|
|
||||||
to allow the user to provide a replacement implementation for the failing instance.
|
|
||||||
Usage: See SOFTCODE_RETRY & SOFTCODE_RETRY_BLOCK below.
|
|
||||||
*/
|
|
||||||
template <typename TPtr, typename TLambda>
|
|
||||||
void SoftCodeRetry(TPtr& pointer, TLambda& lambda)
|
|
||||||
{
|
|
||||||
bool complete = false;
|
|
||||||
while (pointer && !complete)
|
|
||||||
{
|
|
||||||
__try
|
|
||||||
{
|
|
||||||
lambda();
|
|
||||||
complete = true;
|
|
||||||
}
|
|
||||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
|
||||||
{
|
|
||||||
if (gEnv->pSoftCodeMgr)
|
|
||||||
{
|
|
||||||
pointer = reinterpret_cast<TPtr>(gEnv->pSoftCodeMgr->WaitForUpdate(pointer));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Attempts to call an expression based the given pointer.
|
|
||||||
If a Structured Exception is raised the thread will wait for a replacement of
|
|
||||||
the pointer to be provided via the SoftCodeMgr. This will repeat until no exception is raised.
|
|
||||||
|
|
||||||
Usage: SOFTCODE_RETRY(pThing, (pThing->Update(frameTime))); // Same as pThing->Update(frameTime);
|
|
||||||
*/
|
|
||||||
#define SOFTCODE_RETRY(pointer, exp) SoftCodeRetry(pointer, [&](){ exp; })
|
|
||||||
|
|
||||||
/*
|
|
||||||
Attempts to call an expression based the given pointer.
|
|
||||||
If a Structured Exception is raised the thread will wait for a replacement of
|
|
||||||
the pointer to be provided via the SoftCodeMgr. This will repeat until no exception is raised.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
SOFTCODE_RETRY_BLOCK(pThing)
|
|
||||||
{
|
|
||||||
pSomething = pThing->GetSomething();
|
|
||||||
}
|
|
||||||
SOFTCODE_RETRY_END
|
|
||||||
*/
|
|
||||||
#define SOFTCODE_RETRY_BLOCK(pointer) SoftCodeRetry(pointer, [&]() {
|
|
||||||
#define SOFTCODE_RETRY_END });
|
|
||||||
|
|
||||||
#else // !SOFTCODE_ENABLED ...
|
|
||||||
|
|
||||||
// IMPORTANT: Docs for these macros are found above.
|
|
||||||
|
|
||||||
#define DECLARE_TYPELIB(IName) \
|
|
||||||
typedef CTypeLibrary<IName> TLibrary
|
|
||||||
|
|
||||||
#define DECLARE_TYPE(TName, TSuperType) \
|
|
||||||
private: \
|
|
||||||
friend class TypeRegistrar<TName>;
|
|
||||||
|
|
||||||
#define _EXPORT_TYPE_LIB(Interface)
|
|
||||||
|
|
||||||
#define SOFT(member) member
|
|
||||||
#define SOFT_ARRAY(arrayMember)
|
|
||||||
|
|
||||||
#define SOFTCODE_TRY(exp) (exp)
|
|
||||||
#define SOFTCODE_TRY_BLOCK {
|
|
||||||
#define SOFTCODE_TRY_END };
|
|
||||||
|
|
||||||
#define SOFTCODE_RETRY(pointer, exp) (exp)
|
|
||||||
#define SOFTCODE_RETRY_BLOCK(pointer) {
|
|
||||||
#define SOFTCODE_RETRY_END };
|
|
||||||
|
|
||||||
#endif // !SOFTCODE_ENABLED
|
|
||||||
|
|
||||||
/*
|
|
||||||
Implements registration for a type to a TypeLibrary.
|
|
||||||
Usage:
|
|
||||||
// MyThing.cpp
|
|
||||||
DECLARE_TYPE(MyThing);
|
|
||||||
*/
|
|
||||||
#define IMPLEMENT_TYPE(TName) \
|
|
||||||
static TypeRegistrar<TName> s_register##TName(#TName)
|
|
||||||
|
|
||||||
/*
|
|
||||||
Provides the singleton for the TypeLibrary implementation.
|
|
||||||
Also exports the accessors function for SoftCode builds.
|
|
||||||
Usage:
|
|
||||||
// ThingLibrary.cpp
|
|
||||||
IMPLEMENT_TYPELIB(IThing, "Things")
|
|
||||||
*/
|
|
||||||
#define IMPLEMENT_TYPELIB(Interface, Name) \
|
|
||||||
_EXPORT_TYPE_LIB(Interface) \
|
|
||||||
template <> \
|
|
||||||
CTypeLibrary<Interface>* CTypeLibrary<Interface>::Instance() \
|
|
||||||
{ \
|
|
||||||
static CTypeLibrary<Interface> s_instance(Name); \
|
|
||||||
return &s_instance; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Internal: Used to register a type with a TypeLibrary.
|
|
||||||
Also provides instance construction (factory) access.
|
|
||||||
For SC builds it also provides copying and instance tracking.
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
class TypeRegistrar
|
|
||||||
: public ITypeRegistrar
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TypeRegistrar(const char* name)
|
|
||||||
: m_name(name)
|
|
||||||
{
|
|
||||||
typedef typename T::TLibrary TLib;
|
|
||||||
TLib::Instance()->RegisterType(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const char* GetName() const { return m_name; }
|
|
||||||
|
|
||||||
virtual void* CreateInstance()
|
|
||||||
{
|
|
||||||
T* pInstance = NULL;
|
|
||||||
|
|
||||||
SOFTCODE_TRY_BLOCK
|
|
||||||
{
|
|
||||||
pInstance = ConstructInstance();
|
|
||||||
}
|
|
||||||
SOFTCODE_TRY_END
|
|
||||||
|
|
||||||
if (pInstance)
|
|
||||||
{
|
|
||||||
RegisterInstance(pInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
virtual size_t InstanceCount() const
|
|
||||||
{
|
|
||||||
return m_instances.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void RemoveInstance(InstanceTracker* pTracker)
|
|
||||||
{
|
|
||||||
T* pInstance = GetInstanceFromTracker(pTracker);
|
|
||||||
TInstanceVec::iterator iter(std::find(m_instances.begin(), m_instances.end(), pInstance));
|
|
||||||
std::swap(*iter, m_instances.back());
|
|
||||||
m_instances.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool ExchangeInstances(IExchanger& exchanger)
|
|
||||||
{
|
|
||||||
if (exchanger.IsLoading())
|
|
||||||
{
|
|
||||||
const size_t instanceCount = exchanger.InstanceCount();
|
|
||||||
|
|
||||||
// Ensure we have the correct number of instances
|
|
||||||
if (m_instances.size() != instanceCount)
|
|
||||||
{
|
|
||||||
// TODO: Destroy any existing instances
|
|
||||||
for (size_t i = 0; i < instanceCount; ++i)
|
|
||||||
{
|
|
||||||
if (!CreateInstance())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool complete = false;
|
|
||||||
SOFTCODE_TRY_BLOCK
|
|
||||||
{
|
|
||||||
for (std::vector<T*>::iterator iter(m_instances.begin()); iter != m_instances.end(); ++iter)
|
|
||||||
{
|
|
||||||
T* pInstance = *iter;
|
|
||||||
if (exchanger.BeginInstance(pInstance))
|
|
||||||
{
|
|
||||||
// Exchanges the members of pInstance as defined in T
|
|
||||||
// Should also exchange members of parent types
|
|
||||||
pInstance->VisitMembers(exchanger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
complete = true;
|
|
||||||
}
|
|
||||||
SOFTCODE_TRY_END
|
|
||||||
|
|
||||||
return complete;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool DestroyInstances()
|
|
||||||
{
|
|
||||||
bool complete = false;
|
|
||||||
SOFTCODE_TRY_BLOCK
|
|
||||||
{
|
|
||||||
while (!m_instances.empty())
|
|
||||||
{
|
|
||||||
delete m_instances.back();
|
|
||||||
// NOTE: No need to pop_back() as already done by the InstanceTracker via RemoveInstance()
|
|
||||||
}
|
|
||||||
complete = true;
|
|
||||||
}
|
|
||||||
SOFTCODE_TRY_END
|
|
||||||
|
|
||||||
return complete;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool HasInstance(void* pInstance) const
|
|
||||||
{
|
|
||||||
return std::find(m_instances.begin(), m_instances.end(), pInstance) != m_instances.end();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
void RegisterInstance(T* pInstance)
|
|
||||||
{
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
pInstance->__instanceTracker.SetRegistrar(this);
|
|
||||||
m_instances.push_back(pInstance);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
// Util: Avoids having to redundantly store the instance address in the tracker
|
|
||||||
T* GetInstanceFromTracker(InstanceTracker* pTracker)
|
|
||||||
{
|
|
||||||
ptrdiff_t trackerOffset = reinterpret_cast<ptrdiff_t>(&((static_cast<T*>(0))->__instanceTracker));
|
|
||||||
return reinterpret_cast<T*>(reinterpret_cast<char*>(pTracker) - trackerOffset);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Needed to avoid C2712 due to lack of stack unwind within SEH try blocks
|
|
||||||
T* ConstructInstance()
|
|
||||||
{
|
|
||||||
return new T();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const char* m_name; // Name of the type
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
typedef std::vector<T*> TInstanceVec;
|
|
||||||
TInstanceVec m_instances; // Tracks the active instances (SC only)
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
Provides factory creation support for a set of types that
|
|
||||||
derive from a single interface T. Users need to provide a
|
|
||||||
specialization of the static CTypeLibrary<T>* Instance() member
|
|
||||||
in a cpp file to provide the singleton instance.
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
class CTypeLibrary
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
: public ITypeLibrary
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CTypeLibrary(const char* name)
|
|
||||||
: m_name(name)
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
, m_pOverrideLib()
|
|
||||||
, m_overrideActive()
|
|
||||||
, m_registered()
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implemented in the export cpp
|
|
||||||
static CTypeLibrary<T>* Instance();
|
|
||||||
|
|
||||||
void RegisterType(ITypeRegistrar* pType)
|
|
||||||
{
|
|
||||||
m_typeMap[pType->GetName()] = pType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The global identifier for this library module
|
|
||||||
/*virtual*/ const char* GetName() { return m_name; }
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
virtual void* CreateInstanceVoid(const char* typeName)
|
|
||||||
{
|
|
||||||
return CreateInstance(typeName);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Generic creation function
|
|
||||||
T* CreateInstance(const char* typeName)
|
|
||||||
{
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
RegisterWithSoftCode();
|
|
||||||
|
|
||||||
// If override is enabled, use it
|
|
||||||
if (m_pOverrideLib)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<T*>(m_pOverrideLib->CreateInstanceVoid(typeName));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TTypeMap::const_iterator typeIter(m_typeMap.find(typeName));
|
|
||||||
if (typeIter != m_typeMap.end())
|
|
||||||
{
|
|
||||||
ITypeRegistrar* pRegistrar = typeIter->second;
|
|
||||||
return reinterpret_cast<T*>(pRegistrar->CreateInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
// Indicates CreateInstance requests should be forwarded to the specified lib
|
|
||||||
virtual void SetOverride(ITypeLibrary* pOverrideLib)
|
|
||||||
{
|
|
||||||
m_pOverrideLib = pOverrideLib;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual size_t GetTypes(ITypeRegistrar** ppTypes, size_t& count) const
|
|
||||||
{
|
|
||||||
size_t returnedCount = 0;
|
|
||||||
|
|
||||||
if (ppTypes && count >= m_typeMap.size())
|
|
||||||
{
|
|
||||||
for (TTypeMap::const_iterator iter(m_typeMap.begin()); iter != m_typeMap.end(); ++iter)
|
|
||||||
{
|
|
||||||
*ppTypes = iter->second;
|
|
||||||
++ppTypes;
|
|
||||||
++returnedCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
count = m_typeMap.size();
|
|
||||||
return returnedCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inform the Mgr of this Library and allow it to set an override
|
|
||||||
inline void RegisterWithSoftCode()
|
|
||||||
{
|
|
||||||
// Only register built-in types, SC types are handled directly by
|
|
||||||
// the SoftCodeMgr, so there's no need to auto-register.
|
|
||||||
#ifndef SOFTCODE
|
|
||||||
if (!m_registered)
|
|
||||||
{
|
|
||||||
if (ISoftCodeMgr* pSoftCodeMgr = gEnv->pSoftCodeMgr)
|
|
||||||
{
|
|
||||||
pSoftCodeMgr->RegisterLibrary(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_registered = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
typedef AZStd::basic_string<char, AZStd::char_traits<char>, AZ::AZStdAlloc<CryLegacySTLAllocator>> TypeString;
|
|
||||||
typedef AZStd::map<TypeString, ITypeRegistrar*, AZStd::less<TypeString>, AZ::AZStdAlloc<CryLegacySTLAllocator>> TTypeMap;
|
|
||||||
TTypeMap m_typeMap;
|
|
||||||
|
|
||||||
// The name for this TypeLibrary used during SC registration
|
|
||||||
const char* m_name;
|
|
||||||
|
|
||||||
#ifdef SOFTCODE_ENABLED
|
|
||||||
// Used to patch in a new TypeLib at run-time
|
|
||||||
ITypeLibrary* m_pOverrideLib;
|
|
||||||
// True when the owning object system enables the override
|
|
||||||
bool m_overrideActive;
|
|
||||||
// True when registration with SoftCodeMgr has been attempted
|
|
||||||
bool m_registered;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYCOMMON_TYPELIBRARY_H
|
|
||||||
@ -1,251 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include <ITimer.h>
|
|
||||||
#include <CrySizer.h>
|
|
||||||
#include "CrySizerImpl.h"
|
|
||||||
|
|
||||||
CrySizerImpl::CrySizerImpl()
|
|
||||||
: m_pResourceCollector(0)
|
|
||||||
{
|
|
||||||
m_nFlags = 0;
|
|
||||||
m_nTotalSize = 0;
|
|
||||||
// to avoid reallocations during walk through the memory tree, reserve the space for the names
|
|
||||||
clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
CrySizerImpl::~CrySizerImpl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrySizerImpl::Push (const char* szComponentName)
|
|
||||||
{
|
|
||||||
m_stackNames.push_back (getNameIndex(getCurrentName(), szComponentName));
|
|
||||||
// if the depth is too deep, something is wrong, perhaps an infinite loop
|
|
||||||
assert (m_stackNames.size() < 128);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrySizerImpl::PushSubcomponent (const char* szSubcomponentName)
|
|
||||||
{
|
|
||||||
Push (szSubcomponentName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CrySizerImpl::Pop ()
|
|
||||||
{
|
|
||||||
if (!m_stackNames.empty())
|
|
||||||
{
|
|
||||||
m_stackNames.pop_back();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns the index of the current name on the top of the name stack
|
|
||||||
size_t CrySizerImpl::getCurrentName() const
|
|
||||||
{
|
|
||||||
assert(!m_stackNames.empty());
|
|
||||||
return m_stackNames.empty() ? 0 : m_stackNames.back();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// searches for the name in the name array; adds the name if it's not there and returns the index
|
|
||||||
size_t CrySizerImpl::getNameIndex(size_t nParent, const char* szComponentName)
|
|
||||||
{
|
|
||||||
NameArray::const_iterator it = m_arrNames.begin(), itEnd = it + m_arrNames.size();
|
|
||||||
for (; it != itEnd; ++it)
|
|
||||||
{
|
|
||||||
#if defined(LINUX)
|
|
||||||
if (!strcasecmp(it->strName.c_str(), szComponentName) && it->nParent == nParent)
|
|
||||||
#else
|
|
||||||
if (!strcmp(it->strName.c_str(), szComponentName) && it->nParent == nParent)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
return (size_t)(it - m_arrNames.begin());//it-m_arrNames.begin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t nNewName = m_arrNames.size();
|
|
||||||
m_arrNames.resize(nNewName + 1);
|
|
||||||
|
|
||||||
m_arrNames[nNewName].assign(szComponentName, nParent);
|
|
||||||
|
|
||||||
m_arrNames[nParent].arrChildren.push_back(nParent);
|
|
||||||
|
|
||||||
return nNewName;
|
|
||||||
}
|
|
||||||
|
|
||||||
static NullResCollector s_nullCollector;
|
|
||||||
|
|
||||||
IResourceCollector* CrySizerImpl::GetResourceCollector()
|
|
||||||
{
|
|
||||||
return m_pResourceCollector != 0 ? m_pResourceCollector : &s_nullCollector;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrySizerImpl::Reset()
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
|
|
||||||
m_nTotalSize = 0;
|
|
||||||
|
|
||||||
//m_arrNames.resize(0);
|
|
||||||
//m_arrNames.push_back("TOTAL"); // the default name, with index 0
|
|
||||||
//m_LastObject.clear();
|
|
||||||
////m_nFlags;
|
|
||||||
//m_nTotalSize=0;
|
|
||||||
//if (m_pResourceCollector)
|
|
||||||
//{
|
|
||||||
// m_pResourceCollector->Reset();
|
|
||||||
//}
|
|
||||||
//m_setObjects->clear();
|
|
||||||
//m_stackNames.resize(0);
|
|
||||||
//m_stackNames.push_back(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// adds an object identified by the unique pointer (it needs not be
|
|
||||||
// the actual object position in the memory, though it would be nice,
|
|
||||||
// but it must be unique throughout the system and unchanging for this object)
|
|
||||||
// RETURNS: true if the object has actually been added (for the first time)
|
|
||||||
// and calculated
|
|
||||||
bool CrySizerImpl::AddObject (const void* pIdentifier, size_t sizeBytes, int nCount)
|
|
||||||
{
|
|
||||||
if (!pIdentifier || !sizeBytes)
|
|
||||||
{
|
|
||||||
return false; // we don't add the NULL objects
|
|
||||||
}
|
|
||||||
Object NewObject(pIdentifier, sizeBytes, getCurrentName());
|
|
||||||
|
|
||||||
// check if the last object was the same
|
|
||||||
if (NewObject == m_LastObject)
|
|
||||||
{
|
|
||||||
assert (m_LastObject.nSize == sizeBytes);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectSet& rSet = m_setObjects[getHash(pIdentifier)];
|
|
||||||
ObjectSet::iterator it = rSet.find (NewObject);
|
|
||||||
if (it == rSet.end())
|
|
||||||
{
|
|
||||||
// there's no such object in the map, add it
|
|
||||||
rSet.insert (NewObject);
|
|
||||||
ComponentName& CompName = m_arrNames[getCurrentName()];
|
|
||||||
CompName.numObjects += nCount;
|
|
||||||
CompName.sizeObjects += sizeBytes;
|
|
||||||
|
|
||||||
m_nTotalSize += sizeBytes;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Object* pObj = const_cast<Object*>(&(*it));
|
|
||||||
|
|
||||||
// if we do an heap check, don't accept the same object twice
|
|
||||||
if (sizeBytes != pObj->nSize)
|
|
||||||
{
|
|
||||||
// if the following assert fails:
|
|
||||||
// assert (0);
|
|
||||||
// .. it means we have one object that's added two times with different sizes; that's screws up the whole idea
|
|
||||||
// we assume there are two different objects that are for some reason assigned the same id
|
|
||||||
pObj->nSize += sizeBytes; // anyway it's an invalid situation
|
|
||||||
ComponentName& CompName = m_arrNames[getCurrentName()];
|
|
||||||
CompName.sizeObjects += sizeBytes;
|
|
||||||
return true; // yes we added the object, though there were an error condition
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t CrySizerImpl::GetObjectCount()
|
|
||||||
{
|
|
||||||
size_t count = m_stackNames.size();
|
|
||||||
for (int i = 0; i < g_nHashSize; i++)
|
|
||||||
{
|
|
||||||
count += m_setObjects[i].size();
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// finalizes data collection, should be called after all objects have been added
|
|
||||||
void CrySizerImpl::End()
|
|
||||||
{
|
|
||||||
// clean up the totals of each name
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < m_arrNames.size(); ++i)
|
|
||||||
{
|
|
||||||
assert (i == 0 || ((int)m_arrNames[i].nParent < i && m_arrNames[i].nParent >= 0));
|
|
||||||
m_arrNames[i].sizeObjectsTotal = m_arrNames[i].sizeObjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the component's size to the total size of the parent.
|
|
||||||
// for every component, all their children are put after them in the name array
|
|
||||||
// we don't include the root because it doesn't belong to any other parent (nowhere further to add)
|
|
||||||
for (i = m_arrNames.size() - 1; i > 0; --i)
|
|
||||||
{
|
|
||||||
// the parent's total size is increased by the _total_ size (already calculated) of this object
|
|
||||||
m_arrNames[m_arrNames[i].nParent].sizeObjectsTotal += m_arrNames[i].sizeObjectsTotal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CrySizerImpl::clear()
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < g_nHashSize; ++i)
|
|
||||||
{
|
|
||||||
m_setObjects[i].clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_arrNames.clear();
|
|
||||||
m_arrNames.push_back("TOTAL"); // the default name, with index 0
|
|
||||||
m_stackNames.clear();
|
|
||||||
m_stackNames.push_back(0);
|
|
||||||
m_LastObject.pId = NULL;
|
|
||||||
|
|
||||||
if (m_pResourceCollector)
|
|
||||||
{
|
|
||||||
m_pResourceCollector->Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// hash function for an address; returns value 0..1<<g_nHashSize
|
|
||||||
unsigned CrySizerImpl::getHash (const void* pId)
|
|
||||||
{
|
|
||||||
//return (((unsigned)pId) >> 4) & (g_nHashSize-1);
|
|
||||||
|
|
||||||
// pseudorandomizing transform
|
|
||||||
ldiv_t Qrem = (ldiv_t)ldiv(((uint32)(UINT_PTR)pId >> 2), 127773);
|
|
||||||
Qrem.rem = 16807 * Qrem.rem - 2836 * Qrem.quot;
|
|
||||||
if (Qrem.rem < 0)
|
|
||||||
{
|
|
||||||
Qrem.rem += 2147483647; // 0x7FFFFFFF
|
|
||||||
}
|
|
||||||
return ((unsigned)Qrem.rem) & (g_nHashSize - 1);
|
|
||||||
}
|
|
||||||
unsigned CrySizerImpl::GetDepthLevel(unsigned nCurrent)
|
|
||||||
{
|
|
||||||
uint32 nDepth = 0;
|
|
||||||
nCurrent = m_arrNames[nCurrent].nParent;
|
|
||||||
while (nCurrent != 0)
|
|
||||||
{
|
|
||||||
nDepth++;
|
|
||||||
nCurrent = m_arrNames[nCurrent].nParent;
|
|
||||||
}
|
|
||||||
return nDepth;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,184 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Implementation of the ICrySizer interface, which is used to
|
|
||||||
// calculate the memory usage by the subsystems and components, to help
|
|
||||||
// the artists keep the memory budged low.
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_CRYSIZERIMPL_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_CRYSIZERIMPL_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// prerequisities
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// implementation of interface ICrySizer
|
|
||||||
// ICrySizer is passed to all subsystems and has a lot of helper functions that
|
|
||||||
// are compiled in the appropriate subsystems. CrySizerImpl is created in CrySystem
|
|
||||||
// and is passed to all the other subsystems
|
|
||||||
class CrySizerImpl
|
|
||||||
: public ICrySizer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CrySizerImpl();
|
|
||||||
~CrySizerImpl();
|
|
||||||
|
|
||||||
virtual void Release() { delete this; }
|
|
||||||
virtual size_t GetTotalSize() { return m_nTotalSize; };
|
|
||||||
virtual size_t GetObjectCount();
|
|
||||||
|
|
||||||
void Reset();
|
|
||||||
|
|
||||||
// adds an object identified by the unique pointer (it needs not be
|
|
||||||
// the actual object position in the memory, though it would be nice,
|
|
||||||
// but it must be unique throughout the system and unchanging for this object)
|
|
||||||
// RETURNS: true if the object has actually been added (for the first time)
|
|
||||||
// and calculated
|
|
||||||
virtual bool AddObject (const void* pIdentifier, size_t nSizeBytes, int nCount = 1);
|
|
||||||
|
|
||||||
virtual IResourceCollector* GetResourceCollector();
|
|
||||||
|
|
||||||
// finalizes data collection, should be called after all objects have been added
|
|
||||||
void End();
|
|
||||||
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
// Arguments:
|
|
||||||
// pColl - can be 0
|
|
||||||
void SetResourceCollector(IResourceCollector* pColl) { m_pResourceCollector = pColl; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
IResourceCollector* m_pResourceCollector; //
|
|
||||||
|
|
||||||
// these functions must operate on the component name stack
|
|
||||||
// they are to be only accessible from within class CrySizerComponentNameHelper
|
|
||||||
// which should be used through macro SIZER_COMPONENT_NAME
|
|
||||||
virtual void Push (const char* szComponentName);
|
|
||||||
virtual void PushSubcomponent (const char* szSubcomponentName);
|
|
||||||
virtual void Pop ();
|
|
||||||
|
|
||||||
// searches for the name in the name array; adds the name if it's not there and returns the index
|
|
||||||
size_t getNameIndex (size_t nParent, const char* szComponentName);
|
|
||||||
|
|
||||||
// returns the index of the current name on the top of the name stack
|
|
||||||
size_t getCurrentName() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
friend class CrySizerStatsBuilder;
|
|
||||||
|
|
||||||
// the stack of subsystem names; the indices in the name array are kept, not the names themselves
|
|
||||||
typedef DynArray<size_t> NameStack;
|
|
||||||
NameStack m_stackNames;
|
|
||||||
|
|
||||||
// the array of names; each name ever pushed on the stack is present here
|
|
||||||
struct ComponentName
|
|
||||||
{
|
|
||||||
ComponentName (){}
|
|
||||||
ComponentName (const char* szName, size_t parent = 0)
|
|
||||||
: strName (szName)
|
|
||||||
, nParent (parent)
|
|
||||||
, numObjects(0)
|
|
||||||
, sizeObjects (0)
|
|
||||||
, sizeObjectsTotal (0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void assign (const char* szName, size_t parent = 0)
|
|
||||||
{
|
|
||||||
strName = szName;
|
|
||||||
nParent = parent;
|
|
||||||
numObjects = 0;
|
|
||||||
sizeObjects = 0;
|
|
||||||
sizeObjectsTotal = 0;
|
|
||||||
arrChildren.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// the component name, not including the parents' names
|
|
||||||
string strName;
|
|
||||||
// the index of the parent, 0 being the root
|
|
||||||
size_t nParent;
|
|
||||||
// the number of objects within this component
|
|
||||||
size_t numObjects;
|
|
||||||
// the size of the objects belonging to this component, in bytes
|
|
||||||
size_t sizeObjects;
|
|
||||||
// the total size of all objects; gets filled by the end() method of the CrySizerImpl
|
|
||||||
size_t sizeObjectsTotal;
|
|
||||||
// the children components
|
|
||||||
DynArray<size_t> arrChildren;
|
|
||||||
};
|
|
||||||
typedef DynArray<ComponentName> NameArray;
|
|
||||||
NameArray m_arrNames;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// the set of objects and their sizes: the key is the object address/id,
|
|
||||||
// the value is the size of the object and its name (the index of the name actually)
|
|
||||||
struct Object
|
|
||||||
{
|
|
||||||
const void* pId; // unique pointer identifying the object in memory
|
|
||||||
size_t nSize; // the size of the object in bytes
|
|
||||||
size_t nName; // the index of the name in the name array
|
|
||||||
|
|
||||||
Object ()
|
|
||||||
{clear(); }
|
|
||||||
|
|
||||||
Object (const void* id, size_t size = 0, size_t name = 0)
|
|
||||||
: pId(id)
|
|
||||||
, nSize(size)
|
|
||||||
, nName(name) {}
|
|
||||||
|
|
||||||
// the objects are sorted by their Id
|
|
||||||
bool operator < (const Object& right) const {return (UINT_PTR)pId < (UINT_PTR)right.pId; }
|
|
||||||
bool operator < (const void* right) const {return (UINT_PTR)pId < (UINT_PTR)right; }
|
|
||||||
//friend bool operator < (const void* left, const Object& right);
|
|
||||||
|
|
||||||
bool operator == (const Object& right) const {return pId == right.pId; }
|
|
||||||
|
|
||||||
void clear()
|
|
||||||
{
|
|
||||||
pId = NULL;
|
|
||||||
nSize = 0;
|
|
||||||
nName = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
typedef std::set <Object> ObjectSet;
|
|
||||||
// 2^g_nHashPower == the number of subsets comprising the hash
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
g_nHashPower = 12
|
|
||||||
};
|
|
||||||
|
|
||||||
// hash size (number of subsets)
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
g_nHashSize = 1 << g_nHashPower
|
|
||||||
};
|
|
||||||
// hash function for an address; returns value 0..1<<g_nHashSize
|
|
||||||
unsigned getHash (const void* pId);
|
|
||||||
unsigned GetDepthLevel(unsigned nCurrent);
|
|
||||||
|
|
||||||
ObjectSet m_setObjects[g_nHashSize];
|
|
||||||
|
|
||||||
// the last object inserted; this is a small optimization for our template implementaiton
|
|
||||||
// that often can add two times the same object
|
|
||||||
Object m_LastObject;
|
|
||||||
|
|
||||||
size_t m_nTotalSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_CRYSIZERIMPL_H
|
|
||||||
@ -1,484 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "ILog.h"
|
|
||||||
#include "ITimer.h"
|
|
||||||
#include "ISystem.h"
|
|
||||||
#include "IConsole.h"
|
|
||||||
#include "IRenderer.h"
|
|
||||||
#include "CrySizerImpl.h"
|
|
||||||
#include "CrySizerStats.h"
|
|
||||||
#include "ITextModeConsole.h"
|
|
||||||
|
|
||||||
CrySizerStatsBuilder::CrySizerStatsBuilder (CrySizerImpl* pSizer, int nMinSubcomponentBytes)
|
|
||||||
: m_pSizer (pSizer)
|
|
||||||
, m_nMinSubcomponentBytes (nMinSubcomponentBytes < 0 || nMinSubcomponentBytes > 0x10000000 ? 0 : nMinSubcomponentBytes)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// creates the map of names from old (in the sizer Impl) to new (in the Stats)
|
|
||||||
void CrySizerStatsBuilder::processNames()
|
|
||||||
{
|
|
||||||
size_t numCompNames = m_pSizer->m_arrNames.size();
|
|
||||||
m_pStats->m_arrComponents.reserve (numCompNames);
|
|
||||||
m_pStats->m_arrComponents.clear();
|
|
||||||
|
|
||||||
m_mapNames.resize (numCompNames, (size_t)-1);
|
|
||||||
|
|
||||||
// add all root objects
|
|
||||||
addNameSubtree(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// given the name in the old system, adds the subtree of names to the
|
|
||||||
// name map and components. In case all the subtree is empty, returns false and
|
|
||||||
// adds nothing
|
|
||||||
size_t CrySizerStatsBuilder::addNameSubtree (unsigned nDepth, size_t nName)
|
|
||||||
{
|
|
||||||
assert ((int)nName < m_pSizer->m_arrNames.size());
|
|
||||||
|
|
||||||
CrySizerImpl::ComponentName& rCompName = m_pSizer->m_arrNames[nName];
|
|
||||||
size_t sizeObjectsTotal = rCompName.sizeObjectsTotal;
|
|
||||||
|
|
||||||
if (sizeObjectsTotal <= m_nMinSubcomponentBytes)
|
|
||||||
{
|
|
||||||
return sizeObjectsTotal; // the subtree didn't pass
|
|
||||||
}
|
|
||||||
// the index of the component in the stats object (sorted by the depth-first traverse order)
|
|
||||||
size_t nNewName = m_pStats->m_arrComponents.size();
|
|
||||||
m_pStats->m_arrComponents.resize (nNewName + 1);
|
|
||||||
|
|
||||||
Component& rNewComp = m_pStats->m_arrComponents[nNewName];
|
|
||||||
rNewComp.strName = rCompName.strName;
|
|
||||||
rNewComp.nDepth = nDepth;
|
|
||||||
rNewComp.numObjects = rCompName.numObjects;
|
|
||||||
rNewComp.sizeBytes = rCompName.sizeObjects;
|
|
||||||
rNewComp.sizeBytesTotal = sizeObjectsTotal;
|
|
||||||
m_mapNames[nName] = nNewName;
|
|
||||||
|
|
||||||
// find the immediate children and sort them by their total size
|
|
||||||
typedef std::map<size_t, size_t> UintUintMap;
|
|
||||||
UintUintMap mapSizeName; // total size -> child index (name in old indexation)
|
|
||||||
|
|
||||||
for (int i = nName + 1; i < m_pSizer->m_arrNames.size(); ++i)
|
|
||||||
{
|
|
||||||
CrySizerImpl::ComponentName& rChild = m_pSizer->m_arrNames[i];
|
|
||||||
if (rChild.nParent == nName && rChild.sizeObjectsTotal > m_nMinSubcomponentBytes)
|
|
||||||
{
|
|
||||||
mapSizeName.insert (UintUintMap::value_type(rChild.sizeObjectsTotal, i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the sorted components
|
|
||||||
/*
|
|
||||||
for (unsigned i = nName + 1; i < m_pSizer->m_arrNames.size(); ++i)
|
|
||||||
if (m_pSizer->m_arrNames[i].nParent == nName)
|
|
||||||
addNameSubtree(nDepth+1,i);
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (UintUintMap::reverse_iterator it = mapSizeName.rbegin(); it != mapSizeName.rend(); ++it)
|
|
||||||
{
|
|
||||||
addNameSubtree(nDepth + 1, it->second);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sizeObjectsTotal;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// creates the statistics out of the given CrySizerImpl into the given CrySizerStats
|
|
||||||
// Maps the old to new names according to the depth-walk tree rule
|
|
||||||
void CrySizerStatsBuilder::build (CrySizerStats* pStats)
|
|
||||||
{
|
|
||||||
m_pStats = pStats;
|
|
||||||
|
|
||||||
m_mapNames.clear();
|
|
||||||
|
|
||||||
processNames();
|
|
||||||
|
|
||||||
m_pSizer->clear();
|
|
||||||
pStats->refresh();
|
|
||||||
pStats->m_nAgeFrames = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// constructs the statistics based on the given cry sizer
|
|
||||||
CrySizerStats::CrySizerStats (CrySizerImpl* pCrySizer)
|
|
||||||
{
|
|
||||||
CrySizerStatsBuilder builder (pCrySizer);
|
|
||||||
builder.build(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
CrySizerStats::CrySizerStats ()
|
|
||||||
: m_nStartRow(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrySizerStats::updateKeys()
|
|
||||||
{
|
|
||||||
const unsigned int statSize = size();
|
|
||||||
//assume 10 pixels for font
|
|
||||||
unsigned int height = gEnv->pRenderer->GetHeight() / 12;
|
|
||||||
if (CryGetAsyncKeyState(VK_UP))
|
|
||||||
{
|
|
||||||
if (m_nStartRow > 0)
|
|
||||||
{
|
|
||||||
--m_nStartRow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CryGetAsyncKeyState(VK_DOWN))
|
|
||||||
{
|
|
||||||
if (statSize > height + m_nStartRow)
|
|
||||||
{
|
|
||||||
++m_nStartRow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CryGetAsyncKeyState(VK_RIGHT) & 1)
|
|
||||||
{
|
|
||||||
//assume 10 pixels for font
|
|
||||||
if (statSize > height)
|
|
||||||
{
|
|
||||||
m_nStartRow = statSize - height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CryGetAsyncKeyState(VK_LEFT) & 1)
|
|
||||||
{
|
|
||||||
m_nStartRow = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there is already such name in the map, then just returns the index
|
|
||||||
// of the compoentn in the component array; otherwise adds an entry to themap
|
|
||||||
// and to the component array nad returns its index
|
|
||||||
CrySizerStatsBuilder::Component& CrySizerStatsBuilder::mapName (unsigned nName)
|
|
||||||
{
|
|
||||||
assert (m_mapNames[nName] != -1);
|
|
||||||
return m_pStats->m_arrComponents[m_mapNames[nName]];
|
|
||||||
/*
|
|
||||||
IdToIdMap::iterator it = m_mapNames.find (nName);
|
|
||||||
if (it == m_mapNames.end())
|
|
||||||
{
|
|
||||||
unsigned nNewName = m_arrComponents.size();
|
|
||||||
m_mapNames.insert (IdToIdMap::value_type(nName, nNewName));
|
|
||||||
m_arrComponents.resize(nNewName + 1);
|
|
||||||
m_arrComponents[nNewName].strName.swap(m_pSizer->m_arrNames[nName]);
|
|
||||||
return m_arrComponents.back();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert (it->second < m_arrComponents.size());
|
|
||||||
return m_arrComponents[it->second];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// refreshes the statistics built after the component array is built
|
|
||||||
void CrySizerStats::refresh()
|
|
||||||
{
|
|
||||||
m_nMaxNameLength = 0;
|
|
||||||
for (size_t i = 0; i < m_arrComponents.size(); ++i)
|
|
||||||
{
|
|
||||||
size_t nLength = m_arrComponents[i].strName.length() + m_arrComponents[i].nDepth;
|
|
||||||
if (nLength > m_nMaxNameLength)
|
|
||||||
{
|
|
||||||
m_nMaxNameLength = nLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool CrySizerStats::Component::GenericOrder::operator () (const Component& left, const Component& right) const
|
|
||||||
{
|
|
||||||
return left.strName < right.strName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CrySizerStatsRenderer::CrySizerStatsRenderer (ISystem* pSystem, CrySizerStats* pStats, unsigned nMaxSubcomponentDepth, int nMinSubcomponentBytes)
|
|
||||||
: m_pStats(pStats)
|
|
||||||
, m_pRenderer(pSystem->GetIRenderer())
|
|
||||||
, m_pLog (pSystem->GetILog())
|
|
||||||
, m_pTextModeConsole(pSystem->GetITextModeConsole())
|
|
||||||
, m_nMinSubcomponentBytes (nMinSubcomponentBytes < 0 || nMinSubcomponentBytes > 0x10000000 ? 0x8000 : nMinSubcomponentBytes)
|
|
||||||
, m_nMaxSubcomponentDepth (nMaxSubcomponentDepth)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void DrawStatsText(float x, float y, float fScale, float color[4], const char* format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
SDrawTextInfo ti;
|
|
||||||
ti.xscale = fScale;
|
|
||||||
ti.yscale = fScale;
|
|
||||||
ti.color[0] = color[0];
|
|
||||||
ti.color[1] = color[1];
|
|
||||||
ti.color[2] = color[2];
|
|
||||||
ti.color[3] = color[3];
|
|
||||||
ti.flags = eDrawText_2D | eDrawText_FixedSize | eDrawText_Monospace;
|
|
||||||
gEnv->pRenderer->DrawTextQueued(Vec3(x, y, 0.5f), ti, format, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrySizerStatsRenderer::render(bool bRefreshMark)
|
|
||||||
{
|
|
||||||
if (!m_pStats->size())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x, y, dx, dy;
|
|
||||||
m_pRenderer->GetViewport(&x, &y, &dx, &dy);
|
|
||||||
|
|
||||||
// left coordinate of the text
|
|
||||||
unsigned nNameWidth = (unsigned)(m_pStats->getMaxNameLength() + 1);
|
|
||||||
if (nNameWidth < 25)
|
|
||||||
{
|
|
||||||
nNameWidth = 25;
|
|
||||||
}
|
|
||||||
float fCharScaleX = 1.2f;
|
|
||||||
float fLeft = 0;
|
|
||||||
float fTop = 8;
|
|
||||||
float fVStep = 9;
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
const char* szCountStr1 = "count";
|
|
||||||
const char* szCountStr2 = "_____";
|
|
||||||
#else // _DEBUG
|
|
||||||
const char* szCountStr1 = "", * szCountStr2 = "";
|
|
||||||
#endif // _DEBUG
|
|
||||||
|
|
||||||
float fTextColor[4] = {0.9f, 0.85f, 1, 0.85f};
|
|
||||||
DrawStatsText(fLeft, fTop, fCharScaleX, fTextColor,
|
|
||||||
"%-*s total partial %s", nNameWidth, bRefreshMark ? "Memory usage (refresh*)" : "Memory usage (refresh )", szCountStr1);
|
|
||||||
DrawStatsText(fLeft, fTop + fVStep * 0.25f, fCharScaleX, fTextColor,
|
|
||||||
"%*s _____ _______ %s", nNameWidth, "", szCountStr2);
|
|
||||||
|
|
||||||
unsigned nSubgroupDepth = 1;
|
|
||||||
|
|
||||||
// different colors used to paint the statistics subgroups
|
|
||||||
// a new statistic subgroup starts with a new subtree of depth <= specified
|
|
||||||
float fGray = 0;//0.45f;
|
|
||||||
float fLightGray = 0.5f;//0.8f;
|
|
||||||
float fColors[] =
|
|
||||||
{
|
|
||||||
fLightGray, fLightGray, fGray, 1,
|
|
||||||
1, 1, 1, 1,
|
|
||||||
fGray, 1, 1, 1,
|
|
||||||
1, fGray, 1, 1,
|
|
||||||
1, 1, fGray, 1,
|
|
||||||
fGray, fLightGray, 1, 1,
|
|
||||||
fGray, 1, fGray, 1,
|
|
||||||
1, fGray, fGray, 1
|
|
||||||
};
|
|
||||||
float* pColor = fColors;
|
|
||||||
|
|
||||||
unsigned statSize = m_pStats->size();
|
|
||||||
unsigned startRow = m_pStats->row();
|
|
||||||
unsigned i = 0;
|
|
||||||
for (; i < startRow; ++i)
|
|
||||||
{
|
|
||||||
const Component& rComp = (*m_pStats)[i];
|
|
||||||
if (rComp.nDepth <= nSubgroupDepth)
|
|
||||||
{
|
|
||||||
//switch the color
|
|
||||||
pColor += 4;
|
|
||||||
if (pColor >= fColors + sizeof(fColors) / sizeof(fColors[0]))
|
|
||||||
{
|
|
||||||
pColor = fColors;
|
|
||||||
}
|
|
||||||
|
|
||||||
fTop += fVStep * (0.333333f + (nSubgroupDepth - rComp.nDepth) * 0.15f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned r = startRow; i < statSize; ++i)
|
|
||||||
{
|
|
||||||
const Component& rComp = (*m_pStats)[i];
|
|
||||||
if (rComp.nDepth <= nSubgroupDepth)
|
|
||||||
{
|
|
||||||
//switch the color
|
|
||||||
pColor += 4;
|
|
||||||
if (pColor >= fColors + sizeof(fColors) / sizeof(fColors[0]))
|
|
||||||
{
|
|
||||||
pColor = fColors;
|
|
||||||
}
|
|
||||||
|
|
||||||
fTop += fVStep * (0.333333f + (nSubgroupDepth - rComp.nDepth) * 0.15f);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rComp.sizeBytesTotal <= m_nMinSubcomponentBytes || rComp.nDepth > m_nMaxSubcomponentDepth)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
fTop += fVStep;
|
|
||||||
|
|
||||||
char szDepth[32] = " ..............................";
|
|
||||||
if (rComp.nDepth < sizeof(szDepth))
|
|
||||||
{
|
|
||||||
szDepth[rComp.nDepth] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
char szSize[32];
|
|
||||||
if (rComp.sizeBytes > 0)
|
|
||||||
{
|
|
||||||
if (rComp.sizeBytesTotal > rComp.sizeBytes)
|
|
||||||
{
|
|
||||||
azsprintf(szSize, "%7.3f %7.3f", rComp.getTotalSizeMBytes(), rComp.getSizeMBytes());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
azsprintf(szSize, " %7.3f", rComp.getSizeMBytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert (rComp.sizeBytesTotal > 0);
|
|
||||||
azsprintf(szSize, "%7.3f ", rComp.getTotalSizeMBytes());
|
|
||||||
}
|
|
||||||
char szCount[16];
|
|
||||||
#ifdef _DEBUG
|
|
||||||
if (rComp.numObjects)
|
|
||||||
{
|
|
||||||
azsprintf(szCount, "%zd" PRIu64 "", rComp.numObjects);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
szCount[0] = '\0';
|
|
||||||
|
|
||||||
DrawStatsText(fLeft, fTop, fCharScaleX, pColor,
|
|
||||||
"%s%-*s:%s%s", szDepth, nNameWidth - rComp.nDepth, rComp.strName.c_str(), szSize, szCount);
|
|
||||||
|
|
||||||
if (m_pTextModeConsole)
|
|
||||||
{
|
|
||||||
string text;
|
|
||||||
text.Format("%s%-*s:%s%s", szDepth, nNameWidth - rComp.nDepth, rComp.strName.c_str(), szSize, szCount);
|
|
||||||
m_pTextModeConsole->PutText(0, r++, text.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float fLTGrayColor[4] = {fLightGray, fLightGray, fLightGray, 1.0f};
|
|
||||||
fTop += 0.25f * fVStep;
|
|
||||||
DrawStatsText(fLeft, fTop, fCharScaleX, fLTGrayColor,
|
|
||||||
"%-*s %s", nNameWidth, "___________________________", "________________");
|
|
||||||
fTop += fVStep;
|
|
||||||
|
|
||||||
const char* szOverheadNames[CrySizerStats::g_numTimers] =
|
|
||||||
{
|
|
||||||
".Collection",
|
|
||||||
".Transformation",
|
|
||||||
".Cleanup"
|
|
||||||
};
|
|
||||||
bool bOverheadsHeaderPrinted = false;
|
|
||||||
for (i = 0; i < CrySizerStats::g_numTimers; ++i)
|
|
||||||
{
|
|
||||||
float fTime = m_pStats->getTime(i);
|
|
||||||
if (fTime < 20)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// print the header
|
|
||||||
if (!bOverheadsHeaderPrinted)
|
|
||||||
{
|
|
||||||
DrawStatsText(fLeft, fTop, fCharScaleX, fTextColor,
|
|
||||||
"%-*s", nNameWidth, "Overheads");
|
|
||||||
fTop += fVStep;
|
|
||||||
bOverheadsHeaderPrinted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawStatsText(fLeft, fTop, fCharScaleX, fTextColor,
|
|
||||||
"%-*s:%7.1f ms", nNameWidth, szOverheadNames[i], fTime);
|
|
||||||
fTop += fVStep;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrySizerStatsRenderer::dump(bool bUseKB)
|
|
||||||
{
|
|
||||||
if (!m_pStats->size())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned nNameWidth = (unsigned)(m_pStats->getMaxNameLength() + 1);
|
|
||||||
|
|
||||||
// left coordinate of the text
|
|
||||||
m_pLog->LogToFile ("Memory Statistics: %s", bUseKB ? "KB" : "MB");
|
|
||||||
m_pLog->LogToFile("%-*s TOTAL partial count", nNameWidth, "");
|
|
||||||
|
|
||||||
// different colors used to paint the statistics subgroups
|
|
||||||
// a new statistic subgroup starts with a new subtree of depth <= specified
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < m_pStats->size(); ++i)
|
|
||||||
{
|
|
||||||
const Component& rComp = (*m_pStats)[i];
|
|
||||||
|
|
||||||
if (rComp.sizeBytesTotal <= m_nMinSubcomponentBytes || rComp.nDepth > m_nMaxSubcomponentDepth)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char szDepth[32] = " ..............................";
|
|
||||||
if (rComp.nDepth < sizeof(szDepth))
|
|
||||||
{
|
|
||||||
szDepth[rComp.nDepth] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
char szSize[32];
|
|
||||||
if (rComp.sizeBytes > 0)
|
|
||||||
{
|
|
||||||
if (rComp.sizeBytesTotal > rComp.sizeBytes)
|
|
||||||
{
|
|
||||||
azsprintf(szSize, bUseKB ? "%7.2f %7.2f" : "%7.3f %7.3f", bUseKB ? rComp.getTotalSizeKBytes() : rComp.getTotalSizeMBytes(), bUseKB ? rComp.getSizeKBytes() : rComp.getSizeMBytes());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
azsprintf(szSize, bUseKB ? " %7.2f" : " %7.3f", bUseKB ? rComp.getSizeKBytes() : rComp.getSizeMBytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert (rComp.sizeBytesTotal > 0);
|
|
||||||
azsprintf(szSize, bUseKB ? "%7.2f " : "%7.3f ", bUseKB ? rComp.getTotalSizeKBytes() : rComp.getTotalSizeMBytes());
|
|
||||||
}
|
|
||||||
char szCount[16];
|
|
||||||
|
|
||||||
if (rComp.numObjects)
|
|
||||||
{
|
|
||||||
azsprintf(szCount, "%8u", (unsigned int)rComp.numObjects);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
szCount[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pLog->LogToFile ("%s%-*s:%s%s", szDepth, nNameWidth - rComp.nDepth, rComp.strName.c_str(), szSize, szCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CrySizerStats::startTimer(unsigned nTimer, ITimer* pTimer)
|
|
||||||
{
|
|
||||||
assert (nTimer < g_numTimers);
|
|
||||||
m_fTime[nTimer] = pTimer->GetAsyncCurTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrySizerStats::stopTimer(unsigned nTimer, ITimer* pTimer)
|
|
||||||
{
|
|
||||||
assert (nTimer < g_numTimers);
|
|
||||||
m_fTime[nTimer] = 1000 * (pTimer->GetAsyncCurTime() - m_fTime[nTimer]);
|
|
||||||
}
|
|
||||||
@ -1,207 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Declaration of the CrySizerStats class, which is used to
|
|
||||||
// calculate the memory usage by the subsystems and components, to help
|
|
||||||
// the artists keep the memory budged low.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_CRYSIZERSTATS_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_CRYSIZERSTATS_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
class CrySizerImpl;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// This class holds only the necessary statistics data, which can be carried
|
|
||||||
// over a few frames without significant impact on memory usage
|
|
||||||
// CrySizerImpl is an implementation of ICrySizer, which is used to collect
|
|
||||||
// those data; it must be destructed immediately after constructing the Stats
|
|
||||||
// object to avoid excessive memory usage.
|
|
||||||
class CrySizerStats
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// constructs the statistics based on the given cry sizer
|
|
||||||
CrySizerStats (CrySizerImpl* pCrySizer);
|
|
||||||
|
|
||||||
CrySizerStats ();
|
|
||||||
|
|
||||||
// this structure describes one component of the memory size statistics
|
|
||||||
struct Component
|
|
||||||
{
|
|
||||||
Component() {clear(); }
|
|
||||||
Component (const string& name, unsigned size = 0, unsigned num = 0)
|
|
||||||
: strName(name)
|
|
||||||
, sizeBytes(size)
|
|
||||||
, numObjects(num)
|
|
||||||
, nDepth(0) {}
|
|
||||||
void clear()
|
|
||||||
{
|
|
||||||
strName = "";
|
|
||||||
sizeBytes = 0;
|
|
||||||
numObjects = 0;
|
|
||||||
nDepth = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the name of the component, as it appeared in the push() call
|
|
||||||
string strName;
|
|
||||||
// the total size, in bytes, of objects in the component
|
|
||||||
size_t sizeBytes;
|
|
||||||
// the total size including the subcomponents
|
|
||||||
size_t sizeBytesTotal;
|
|
||||||
// the number of objects allocated
|
|
||||||
size_t numObjects;
|
|
||||||
unsigned nDepth;
|
|
||||||
|
|
||||||
float getSizeKBytes() const {return sizeBytes / float(1 << 10); }
|
|
||||||
|
|
||||||
float getTotalSizeKBytes () const {return sizeBytesTotal / float(1 << 10); }
|
|
||||||
|
|
||||||
float getSizeMBytes() const {return sizeBytes / float(1 << 20); }
|
|
||||||
|
|
||||||
float getTotalSizeMBytes () const {return sizeBytesTotal / float(1 << 20); }
|
|
||||||
|
|
||||||
struct NameOrder
|
|
||||||
{
|
|
||||||
bool operator () (const Component& left, const Component& right) const {return left.strName < right.strName; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SizeOrder
|
|
||||||
{
|
|
||||||
bool operator () (const Component& left, const Component& right) const {return left.sizeBytes < right.sizeBytes; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GenericOrder
|
|
||||||
{
|
|
||||||
bool operator () (const Component& left, const Component& right) const;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// returns the number of different subsystems/components used
|
|
||||||
unsigned numComponents() const {return (unsigned)m_arrComponents.size(); }
|
|
||||||
// returns the name of the i-th component
|
|
||||||
const Component& getComponent(unsigned nComponent) const {return m_arrComponents[nComponent]; }
|
|
||||||
|
|
||||||
unsigned size() const {return numComponents(); }
|
|
||||||
const Component& operator [] (unsigned i) const {return getComponent(i); }
|
|
||||||
const Component& operator [] (signed i) const {return getComponent(i); }
|
|
||||||
|
|
||||||
unsigned row() const {return m_nStartRow; }
|
|
||||||
void updateKeys();
|
|
||||||
|
|
||||||
size_t getMaxNameLength() const {return m_nMaxNameLength; }
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
g_numTimers = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
void startTimer(unsigned nTimer, ITimer* pTimer);
|
|
||||||
void stopTimer(unsigned nTimer, ITimer* pTimer);
|
|
||||||
float getTime(unsigned nTimer) const {assert (nTimer < g_numTimers); return m_fTime[nTimer]; }
|
|
||||||
int getAgeFrames() const {return m_nAgeFrames; }
|
|
||||||
void incAgeFrames() {++m_nAgeFrames; }
|
|
||||||
protected:
|
|
||||||
// refreshes the statistics built after the component array is built
|
|
||||||
void refresh();
|
|
||||||
protected:
|
|
||||||
// the names of the components
|
|
||||||
typedef std::vector<Component> ComponentArray;
|
|
||||||
ComponentArray m_arrComponents;
|
|
||||||
|
|
||||||
// the maximum length of the component name, in characters
|
|
||||||
size_t m_nMaxNameLength;
|
|
||||||
|
|
||||||
// the timer that counts the time spent on statistics gathering
|
|
||||||
float m_fTime[g_numTimers];
|
|
||||||
|
|
||||||
// the age of the statistics, in frames
|
|
||||||
int m_nAgeFrames;
|
|
||||||
|
|
||||||
//current row offset inc/dec by cursor keys
|
|
||||||
unsigned m_nStartRow;
|
|
||||||
|
|
||||||
friend class CrySizerStatsBuilder;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// this is the constructor for the CrySizerStats
|
|
||||||
class CrySizerStatsBuilder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CrySizerStatsBuilder (CrySizerImpl* pSizer, int nMinSubcomponentBytes = 0);
|
|
||||||
|
|
||||||
void build (CrySizerStats* pStats);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
typedef CrySizerStats::Component Component;
|
|
||||||
// if there is already such name in the map, then just returns the index
|
|
||||||
// of the compoentn in the component array; otherwise adds an entry to themap
|
|
||||||
// and to the component array nad returns its index
|
|
||||||
Component& mapName (unsigned nName);
|
|
||||||
|
|
||||||
// creates the map of names from old to new, and initializes the components themselves
|
|
||||||
void processNames();
|
|
||||||
|
|
||||||
// given the name in the old system, adds the subtree of names to the
|
|
||||||
// name map and components. In case all the subtree is empty, returns 0 and
|
|
||||||
// adds nothing. Otherwise, returns the total size of objects belonging to the
|
|
||||||
// subtree
|
|
||||||
size_t addNameSubtree (unsigned nDepth, size_t nName);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CrySizerStats* m_pStats;
|
|
||||||
CrySizerImpl* m_pSizer;
|
|
||||||
|
|
||||||
// this is the mapping from the old names into the new componentn indices
|
|
||||||
typedef std::vector<size_t> IdToIdMap;
|
|
||||||
// from old to new
|
|
||||||
IdToIdMap m_mapNames;
|
|
||||||
|
|
||||||
// this is the threshold: if the total number of bytes in the subcomponent
|
|
||||||
// is less than this, the subcomponent isn't shown
|
|
||||||
unsigned m_nMinSubcomponentBytes;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Renders the given usage stats; gets created upon every rendering
|
|
||||||
class CrySizerStatsRenderer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// constructor
|
|
||||||
CrySizerStatsRenderer (ISystem* pSystem, CrySizerStats* pStats, unsigned nMaxDepth = 2, int nMinSubcomponentBytes = -1);
|
|
||||||
void render(bool bRefreshMark = false);
|
|
||||||
// dumps it to log. uses MB as default
|
|
||||||
void dump (bool bUseKB = false);
|
|
||||||
|
|
||||||
protected: // -------------------------------------------------
|
|
||||||
|
|
||||||
typedef CrySizerStats::Component Component;
|
|
||||||
|
|
||||||
IRenderer* m_pRenderer; //
|
|
||||||
ILog* m_pLog; //
|
|
||||||
CrySizerStats* m_pStats; //
|
|
||||||
|
|
||||||
ITextModeConsole* m_pTextModeConsole;
|
|
||||||
|
|
||||||
// this is the threshold: if the total number of bytes in the subcomponent
|
|
||||||
// is less than this, the subcomponent isn't shown
|
|
||||||
unsigned m_nMinSubcomponentBytes;
|
|
||||||
|
|
||||||
// the max depth of the branch to output
|
|
||||||
unsigned m_nMaxSubcomponentDepth;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_CRYSIZERSTATS_H
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,712 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_DEFRAGALLOCATOR_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_DEFRAGALLOCATOR_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "IDefragAllocator.h"
|
|
||||||
|
|
||||||
#include "System.h"
|
|
||||||
|
|
||||||
#ifndef _RELEASE
|
|
||||||
#define CDBA_DEBUG
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//#define CDBA_MORE_DEBUG
|
|
||||||
|
|
||||||
#ifdef CDBA_DEBUG
|
|
||||||
#define CDBA_ASSERT(x) do { assert(x); if (!(x)) {__debugbreak(); } \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define CDBA_ASSERT(x) assert(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
union SDefragAllocChunkAttr
|
|
||||||
{
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
SizeWidth = 27,
|
|
||||||
SizeMask = (1 << SizeWidth) - 1,
|
|
||||||
BusyMask = 1 << 27,
|
|
||||||
MovingMask = 1 << 28,
|
|
||||||
MaxPinCount = 7,
|
|
||||||
PinnedCountShift = 29,
|
|
||||||
PinnedIncMask = 1 << PinnedCountShift,
|
|
||||||
PinnedCountMask = MaxPinCount << PinnedCountShift,
|
|
||||||
};
|
|
||||||
|
|
||||||
uint32 ui;
|
|
||||||
|
|
||||||
ILINE unsigned int GetSize() const { return ui & SizeMask; }
|
|
||||||
ILINE void SetSize(unsigned int size) { ui = (ui & ~SizeMask) | size; }
|
|
||||||
ILINE void AddSize(int size) { ui += size; }
|
|
||||||
ILINE bool IsBusy() const { return (ui & BusyMask) != 0; }
|
|
||||||
ILINE void SetBusy(bool b) { ui = b ? (ui | BusyMask) : (ui & ~BusyMask); }
|
|
||||||
ILINE bool IsMoving() const { return (ui & MovingMask) != 0; }
|
|
||||||
ILINE void SetMoving(bool m) { ui = m ? (ui | MovingMask) : (ui & ~MovingMask); }
|
|
||||||
ILINE void IncPinCount() { ui += PinnedIncMask; }
|
|
||||||
ILINE void DecPinCount() { ui -= PinnedIncMask; }
|
|
||||||
ILINE bool IsPinned() const { return (ui & PinnedCountMask) != 0; }
|
|
||||||
ILINE unsigned int GetPinCount() const { return (ui & PinnedCountMask) >> PinnedCountShift; }
|
|
||||||
ILINE void SetPinCount(unsigned int p) { ui = (ui & ~PinnedCountMask) | (p << PinnedCountShift); }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SDefragAllocChunk
|
|
||||||
{
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
AlignBitCount = 4,
|
|
||||||
};
|
|
||||||
typedef IDefragAllocator::Hdl Index;
|
|
||||||
|
|
||||||
Index addrPrevIdx;
|
|
||||||
Index addrNextIdx;
|
|
||||||
|
|
||||||
union
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
UINT_PTR ptr : sizeof(UINT_PTR) * 8 - AlignBitCount;
|
|
||||||
UINT_PTR logAlign: AlignBitCount;
|
|
||||||
};
|
|
||||||
UINT_PTR packedPtr;
|
|
||||||
};
|
|
||||||
SDefragAllocChunkAttr attr;
|
|
||||||
|
|
||||||
union
|
|
||||||
{
|
|
||||||
void* pContext;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
Index freePrevIdx;
|
|
||||||
Index freeNextIdx;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef _RELEASE
|
|
||||||
const char* source;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SwapEndian()
|
|
||||||
{
|
|
||||||
::SwapEndian(addrPrevIdx, true);
|
|
||||||
::SwapEndian(addrNextIdx, true);
|
|
||||||
::SwapEndian(packedPtr, true);
|
|
||||||
::SwapEndian(attr.ui, true);
|
|
||||||
|
|
||||||
if (attr.IsBusy())
|
|
||||||
{
|
|
||||||
::SwapEndian(pContext, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
::SwapEndian(freePrevIdx, true);
|
|
||||||
::SwapEndian(freeNextIdx, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef _RELEASE
|
|
||||||
::SwapEndian(source, true);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SDefragAllocSegment
|
|
||||||
{
|
|
||||||
uint32 address;
|
|
||||||
uint32 capacity;
|
|
||||||
SDefragAllocChunk::Index headSentinalChunkIdx;
|
|
||||||
|
|
||||||
void SwapEndian()
|
|
||||||
{
|
|
||||||
::SwapEndian(address, true);
|
|
||||||
::SwapEndian(capacity, true);
|
|
||||||
::SwapEndian(headSentinalChunkIdx, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CDefragAllocator;
|
|
||||||
|
|
||||||
class CDefragAllocatorWalker
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit CDefragAllocatorWalker(CDefragAllocator& alloc);
|
|
||||||
~CDefragAllocatorWalker();
|
|
||||||
|
|
||||||
const SDefragAllocChunk* Next();
|
|
||||||
|
|
||||||
private:
|
|
||||||
CDefragAllocatorWalker(const CDefragAllocatorWalker&);
|
|
||||||
CDefragAllocatorWalker& operator = (const CDefragAllocatorWalker&);
|
|
||||||
|
|
||||||
private:
|
|
||||||
CDefragAllocator* m_pAlloc;
|
|
||||||
SDefragAllocChunk::Index m_nChunkIdx;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CDefragAllocator
|
|
||||||
: public IDefragAllocator
|
|
||||||
{
|
|
||||||
friend class CDefragAllocatorWalker;
|
|
||||||
typedef SDefragAllocChunk::Index Index;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CDefragAllocator();
|
|
||||||
|
|
||||||
void Release(bool bDiscard);
|
|
||||||
|
|
||||||
void Init(UINT_PTR capacity, UINT_PTR minAlignment, const Policy& policy);
|
|
||||||
|
|
||||||
#ifndef _RELEASE
|
|
||||||
void DumpState(const char* filename);
|
|
||||||
void RestoreState(const char* filename);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// allocatorDisplayOffset will offset the statistics for the allocator depending on the index.
|
|
||||||
// 0 means no offset and default location, 1 means bar will be rendered above the 0th bar and stats to the right of the 0th stats
|
|
||||||
void DisplayMemoryUsage(const char* title, unsigned int allocatorDisplayOffset = 0);
|
|
||||||
|
|
||||||
bool AppendSegment(UINT_PTR capacity);
|
|
||||||
void UnAppendSegment();
|
|
||||||
|
|
||||||
Hdl Allocate(size_t sz, const char* source, void* pContext = NULL);
|
|
||||||
Hdl AllocateAligned(size_t sz, size_t alignment, const char* source, void* pContext = NULL);
|
|
||||||
AllocatePinnedResult AllocatePinned(size_t sz, const char* source, void* pContext = NULL);
|
|
||||||
bool Free(Hdl hdl);
|
|
||||||
|
|
||||||
void ChangeContext(Hdl hdl, void* pNewContext);
|
|
||||||
|
|
||||||
size_t GetAllocated() const { return (size_t)(m_capacity - m_available) << m_logMinAlignment; }
|
|
||||||
IDefragAllocatorStats GetStats();
|
|
||||||
|
|
||||||
size_t DefragmentTick(size_t maxMoves, size_t maxAmount, bool bForce);
|
|
||||||
|
|
||||||
ILINE UINT_PTR UsableSize(Hdl hdl)
|
|
||||||
{
|
|
||||||
Index chunkIdx = ChunkIdxFromHdl(hdl);
|
|
||||||
CDBA_ASSERT(chunkIdx < m_chunks.size());
|
|
||||||
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[chunkIdx];
|
|
||||||
SDefragAllocChunkAttr attr = chunk.attr;
|
|
||||||
|
|
||||||
CDBA_ASSERT(attr.IsBusy());
|
|
||||||
return (UINT_PTR)attr.GetSize() << m_logMinAlignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pin the chunk until the next defrag tick, when it will be automatically unpinned
|
|
||||||
ILINE UINT_PTR WeakPin(Hdl hdl)
|
|
||||||
{
|
|
||||||
Index chunkIdx = ChunkIdxFromHdl(hdl);
|
|
||||||
CDBA_ASSERT(chunkIdx < m_chunks.size());
|
|
||||||
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[chunkIdx];
|
|
||||||
SDefragAllocChunkAttr attr = chunk.attr;
|
|
||||||
CDBA_ASSERT(attr.IsBusy());
|
|
||||||
|
|
||||||
if (attr.IsMoving())
|
|
||||||
{
|
|
||||||
CancelMove(chunkIdx, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return chunk.ptr << m_logMinAlignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pin the chunk until Unpin is called
|
|
||||||
ILINE UINT_PTR Pin(Hdl hdl)
|
|
||||||
{
|
|
||||||
Index chunkIdx = ChunkIdxFromHdl(hdl);
|
|
||||||
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[chunkIdx];
|
|
||||||
SDefragAllocChunkAttr attr;
|
|
||||||
SDefragAllocChunkAttr newAttr;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
attr.ui = const_cast<volatile uint32&>(chunk.attr.ui);
|
|
||||||
newAttr.ui = attr.ui;
|
|
||||||
|
|
||||||
CDBA_ASSERT(attr.GetPinCount() < SDefragAllocChunkAttr::MaxPinCount);
|
|
||||||
CDBA_ASSERT(attr.IsBusy());
|
|
||||||
|
|
||||||
newAttr.IncPinCount();
|
|
||||||
}
|
|
||||||
while (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&chunk.attr.ui), newAttr.ui, attr.ui) != attr.ui);
|
|
||||||
|
|
||||||
// Potentially a Relocate could be in progress here. Either the Relocate is mid-way, in which case 'IsMoving()' will
|
|
||||||
// still be set, and CancelMove will sync and all is well.
|
|
||||||
|
|
||||||
// If 'IsMoving()' is not set, the Relocate should have just completed, in which case ptr should validly point
|
|
||||||
// to the new location.
|
|
||||||
|
|
||||||
if (attr.IsMoving())
|
|
||||||
{
|
|
||||||
CancelMove(chunkIdx, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return chunk.ptr << m_logMinAlignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
ILINE void Unpin(Hdl hdl)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[ChunkIdxFromHdl(hdl)];
|
|
||||||
SDefragAllocChunkAttr attr;
|
|
||||||
SDefragAllocChunkAttr newAttr;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
attr.ui = const_cast<volatile uint32&>(chunk.attr.ui);
|
|
||||||
newAttr.ui = attr.ui;
|
|
||||||
|
|
||||||
CDBA_ASSERT(attr.IsPinned());
|
|
||||||
CDBA_ASSERT(attr.IsBusy());
|
|
||||||
|
|
||||||
newAttr.DecPinCount();
|
|
||||||
}
|
|
||||||
while (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&chunk.attr.ui), newAttr.ui, attr.ui) != attr.ui);
|
|
||||||
}
|
|
||||||
|
|
||||||
ILINE const char* GetSourceOf([[maybe_unused]] Hdl hdl)
|
|
||||||
{
|
|
||||||
#ifndef _RELEASE
|
|
||||||
return m_chunks[ChunkIdxFromHdl(hdl)].source;
|
|
||||||
#else
|
|
||||||
return "";
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
NumBuckets = 31, // 2GB
|
|
||||||
MaxPendingMoves = 64,
|
|
||||||
|
|
||||||
AddrStartSentinal = 0,
|
|
||||||
AddrEndSentinal = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SplitResult
|
|
||||||
{
|
|
||||||
bool bSuccessful;
|
|
||||||
Index nLeftSplitChunkIdx;
|
|
||||||
Index nRightSplitChunkIdx;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PendingMove
|
|
||||||
{
|
|
||||||
PendingMove()
|
|
||||||
: srcChunkIdx(InvalidChunkIdx)
|
|
||||||
, dstChunkIdx(InvalidChunkIdx)
|
|
||||||
, userMoveId(0)
|
|
||||||
, relocated(false)
|
|
||||||
, cancelled(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Index srcChunkIdx;
|
|
||||||
Index dstChunkIdx;
|
|
||||||
uint32 userMoveId;
|
|
||||||
IDefragAllocatorCopyNotification notify;
|
|
||||||
bool relocated;
|
|
||||||
bool cancelled;
|
|
||||||
|
|
||||||
void SwapEndian()
|
|
||||||
{
|
|
||||||
::SwapEndian(srcChunkIdx, true);
|
|
||||||
::SwapEndian(dstChunkIdx, true);
|
|
||||||
::SwapEndian(userMoveId, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PendingMoveSrcChunkPredicate
|
|
||||||
{
|
|
||||||
PendingMoveSrcChunkPredicate(Index ci)
|
|
||||||
: m_ci(ci) {}
|
|
||||||
bool operator () (const PendingMove& pm) const { return pm.srcChunkIdx == m_ci; }
|
|
||||||
Index m_ci;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef DynArray<PendingMove> PendingMoveVec;
|
|
||||||
typedef std::vector<SDefragAllocSegment> SegmentVec;
|
|
||||||
|
|
||||||
static const Index InvalidChunkIdx = (Index) - 1;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static ILINE Index ChunkIdxFromHdl(Hdl id) { return id - 1; }
|
|
||||||
static ILINE Hdl ChunkHdlFromIdx(Index idx) { return idx + 1; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
~CDefragAllocator();
|
|
||||||
|
|
||||||
Index AllocateChunk();
|
|
||||||
void ReleaseChunk(Index idx);
|
|
||||||
|
|
||||||
ILINE void MarkAsInUse(SDefragAllocChunk& chunk)
|
|
||||||
{
|
|
||||||
CDBA_ASSERT(!chunk.attr.IsBusy());
|
|
||||||
|
|
||||||
chunk.attr.SetBusy(true);
|
|
||||||
m_available -= chunk.attr.GetSize();
|
|
||||||
++m_numAllocs;
|
|
||||||
|
|
||||||
// m_available is unsigned, so check for underflow
|
|
||||||
CDBA_ASSERT(m_available <= m_capacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
ILINE void MarkAsFree(SDefragAllocChunk& chunk)
|
|
||||||
{
|
|
||||||
CDBA_ASSERT(chunk.attr.IsBusy());
|
|
||||||
|
|
||||||
chunk.attr.SetPinCount(0);
|
|
||||||
chunk.attr.SetMoving(false);
|
|
||||||
chunk.attr.SetBusy(0);
|
|
||||||
m_available += chunk.attr.GetSize();
|
|
||||||
--m_numAllocs;
|
|
||||||
|
|
||||||
// m_available is unsigned, so check for underflow
|
|
||||||
CDBA_ASSERT(m_available <= m_capacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LinkFreeChunk(Index idx);
|
|
||||||
void UnlinkFreeChunk(Index idx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[idx];
|
|
||||||
m_chunks[chunk.freePrevIdx].freeNextIdx = chunk.freeNextIdx;
|
|
||||||
m_chunks[chunk.freeNextIdx].freePrevIdx = chunk.freePrevIdx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LinkAddrChunk(Index idx, Index afterIdx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[idx];
|
|
||||||
SDefragAllocChunk& afterChunk = m_chunks[afterIdx];
|
|
||||||
|
|
||||||
chunk.addrNextIdx = afterChunk.addrNextIdx;
|
|
||||||
chunk.addrPrevIdx = afterIdx;
|
|
||||||
m_chunks[chunk.addrNextIdx].addrPrevIdx = idx;
|
|
||||||
afterChunk.addrNextIdx = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnlinkAddrChunk(Index id)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[id];
|
|
||||||
|
|
||||||
m_chunks[chunk.addrPrevIdx].addrNextIdx = chunk.addrNextIdx;
|
|
||||||
m_chunks[chunk.addrNextIdx].addrPrevIdx = chunk.addrPrevIdx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrepareMergePopNext(Index* pLists)
|
|
||||||
{
|
|
||||||
for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx)
|
|
||||||
{
|
|
||||||
Index hdrChunkId = m_freeBuckets[bucketIdx];
|
|
||||||
Index nextId = m_chunks[hdrChunkId].freeNextIdx;
|
|
||||||
if (nextId != hdrChunkId)
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = nextId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = InvalidChunkIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t MergePeekNextChunk(Index* pLists)
|
|
||||||
{
|
|
||||||
size_t farList = (size_t)-1;
|
|
||||||
UINT_PTR farPtr = (UINT_PTR)-1;
|
|
||||||
|
|
||||||
for (size_t listIdx = 0; listIdx < NumBuckets; ++listIdx)
|
|
||||||
{
|
|
||||||
Index chunkIdx = pLists[listIdx];
|
|
||||||
if (chunkIdx != InvalidChunkIdx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[chunkIdx];
|
|
||||||
if (chunk.ptr < farPtr)
|
|
||||||
{
|
|
||||||
farPtr = chunk.ptr;
|
|
||||||
farList = listIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return farList;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MergePopNextChunk(Index* pLists, size_t list)
|
|
||||||
{
|
|
||||||
using std::swap;
|
|
||||||
|
|
||||||
Index fni = m_chunks[pLists[list]].freeNextIdx;
|
|
||||||
pLists[list] = fni;
|
|
||||||
if (m_chunks[fni].attr.IsBusy())
|
|
||||||
{
|
|
||||||
// End of the list
|
|
||||||
pLists[list] = InvalidChunkIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MergePatchNextRemove(Index* pLists, Index removeIdx)
|
|
||||||
{
|
|
||||||
for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx)
|
|
||||||
{
|
|
||||||
if (pLists[bucketIdx] == removeIdx)
|
|
||||||
{
|
|
||||||
Index nextIdx = m_chunks[removeIdx].freeNextIdx;
|
|
||||||
if (!m_chunks[nextIdx].attr.IsBusy())
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = nextIdx;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = InvalidChunkIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MergePatchNextInsert(Index* pLists, Index insertIdx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& insertChunk = m_chunks[insertIdx];
|
|
||||||
int bucket = BucketForSize(insertChunk.attr.GetSize());
|
|
||||||
|
|
||||||
if (pLists[bucket] != InvalidChunkIdx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& listChunk = m_chunks[pLists[bucket]];
|
|
||||||
if (listChunk.ptr > insertChunk.ptr)
|
|
||||||
{
|
|
||||||
pLists[bucket] = insertIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrepareMergePopPrev(Index* pLists)
|
|
||||||
{
|
|
||||||
for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx)
|
|
||||||
{
|
|
||||||
Index hdrChunkId = m_freeBuckets[bucketIdx];
|
|
||||||
Index prevIdx = m_chunks[hdrChunkId].freePrevIdx;
|
|
||||||
if (prevIdx != hdrChunkId)
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = prevIdx;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = InvalidChunkIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t MergePeekPrevChunk(Index* pLists)
|
|
||||||
{
|
|
||||||
size_t farList = (size_t)-1;
|
|
||||||
UINT_PTR farPtr = 0;
|
|
||||||
|
|
||||||
for (size_t listIdx = 0; listIdx < NumBuckets; ++listIdx)
|
|
||||||
{
|
|
||||||
Index chunkIdx = pLists[listIdx];
|
|
||||||
if (chunkIdx != InvalidChunkIdx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& chunk = m_chunks[chunkIdx];
|
|
||||||
if (chunk.ptr >= farPtr)
|
|
||||||
{
|
|
||||||
farPtr = chunk.ptr;
|
|
||||||
farList = listIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return farList;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MergePopPrevChunk(Index* pLists, size_t list)
|
|
||||||
{
|
|
||||||
using std::swap;
|
|
||||||
|
|
||||||
Index fpi = m_chunks[pLists[list]].freePrevIdx;
|
|
||||||
pLists[list] = fpi;
|
|
||||||
if (m_chunks[fpi].attr.IsBusy())
|
|
||||||
{
|
|
||||||
// End of the list
|
|
||||||
pLists[list] = InvalidChunkIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MergePatchPrevInsert(Index* pLists, Index insertIdx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& insertChunk = m_chunks[insertIdx];
|
|
||||||
int bucket = BucketForSize(insertChunk.attr.GetSize());
|
|
||||||
|
|
||||||
if (pLists[bucket] != InvalidChunkIdx)
|
|
||||||
{
|
|
||||||
SDefragAllocChunk& listChunk = m_chunks[pLists[bucket]];
|
|
||||||
if (listChunk.ptr < insertChunk.ptr)
|
|
||||||
{
|
|
||||||
pLists[bucket] = insertIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MergePatchPrevRemove(Index* pLists, Index removeIdx)
|
|
||||||
{
|
|
||||||
for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx)
|
|
||||||
{
|
|
||||||
if (pLists[bucketIdx] == removeIdx)
|
|
||||||
{
|
|
||||||
Index nextIdx = m_chunks[removeIdx].freePrevIdx;
|
|
||||||
if (!m_chunks[nextIdx].attr.IsBusy())
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = nextIdx;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pLists[bucketIdx] = InvalidChunkIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarkAsMoving(SDefragAllocChunk& src)
|
|
||||||
{
|
|
||||||
SDefragAllocChunkAttr srcAttr, srcNewAttr;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
srcAttr.ui = const_cast<volatile uint32&>(src.attr.ui);
|
|
||||||
srcNewAttr.ui = srcAttr.ui;
|
|
||||||
srcNewAttr.SetMoving(true);
|
|
||||||
}
|
|
||||||
while (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&src.attr.ui), srcNewAttr.ui, srcAttr.ui) != srcAttr.ui);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarkAsNotMoving(SDefragAllocChunk& src)
|
|
||||||
{
|
|
||||||
SDefragAllocChunkAttr srcAttr, srcNewAttr;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
srcAttr.ui = const_cast<volatile uint32&>(src.attr.ui);
|
|
||||||
srcNewAttr.ui = srcAttr.ui;
|
|
||||||
srcNewAttr.SetMoving(false);
|
|
||||||
}
|
|
||||||
while (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&src.attr.ui), srcNewAttr.ui, srcAttr.ui) != srcAttr.ui);
|
|
||||||
}
|
|
||||||
|
|
||||||
ILINE bool IsMoveableCandidate(const SDefragAllocChunkAttr& a, uint32 sizeUpperBound)
|
|
||||||
{
|
|
||||||
return a.IsBusy() && !a.IsPinned() && !a.IsMoving() && (0 < a.GetSize()) && (a.GetSize() <= sizeUpperBound);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TryMarkAsMoving(SDefragAllocChunk& src, uint32 sizeUpperBound)
|
|
||||||
{
|
|
||||||
SDefragAllocChunkAttr srcAttr, srcNewAttr;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
srcAttr.ui = const_cast<volatile uint32&>(src.attr.ui);
|
|
||||||
srcNewAttr.ui = srcAttr.ui;
|
|
||||||
if (!IsMoveableCandidate(srcAttr, sizeUpperBound))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
srcNewAttr.SetMoving(true);
|
|
||||||
}
|
|
||||||
while (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&src.attr.ui), srcNewAttr.ui, srcAttr.ui) != srcAttr.ui);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TryScheduleCopy(SDefragAllocChunk& srcChunk, SDefragAllocChunk& dstChunk, PendingMove* pPM, bool bLowHalf)
|
|
||||||
{
|
|
||||||
UINT_PTR dstChunkBase = dstChunk.ptr;
|
|
||||||
UINT_PTR dstChunkEnd = dstChunkBase + dstChunk.attr.GetSize();
|
|
||||||
#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64
|
|
||||||
UINT_PTR allocAlign = BIT64(srcChunk.logAlign);
|
|
||||||
#else
|
|
||||||
UINT_PTR allocAlign = BIT(srcChunk.logAlign);
|
|
||||||
#endif
|
|
||||||
UINT_PTR allocSize = srcChunk.attr.GetSize();
|
|
||||||
UINT_PTR dstAllocBase = bLowHalf
|
|
||||||
? Align(dstChunkBase, allocAlign)
|
|
||||||
: ((dstChunkEnd - allocSize) & ~(allocAlign - 1));
|
|
||||||
|
|
||||||
uint32 userId = m_policy.pDefragPolicy->BeginCopy(
|
|
||||||
srcChunk.pContext,
|
|
||||||
dstAllocBase << m_logMinAlignment,
|
|
||||||
srcChunk.ptr << m_logMinAlignment,
|
|
||||||
allocSize << m_logMinAlignment,
|
|
||||||
&pPM->notify);
|
|
||||||
pPM->userMoveId = userId;
|
|
||||||
|
|
||||||
return userId != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Hdl Allocate_Locked(size_t sz, size_t alignment, const char* source, void* pContext);
|
|
||||||
SplitResult SplitFreeBlock(Index fbId, size_t sz, size_t alignment, bool allocateInLowHalf);
|
|
||||||
Index MergeFreeBlock(Index fbId);
|
|
||||||
|
|
||||||
#ifdef CDBA_MORE_DEBUG
|
|
||||||
void Defrag_ValidateFreeBlockIteration();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Index BestFit_FindFreeBlockForSegment(size_t sz, size_t alignment, uint32 nSegment);
|
|
||||||
Index BestFit_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressMin, UINT_PTR addressMax, bool allocateInLowHalf);
|
|
||||||
Index FirstFit_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressMin, UINT_PTR addressMax, bool allocateInLowHalf);
|
|
||||||
|
|
||||||
size_t Defrag_FindMovesBwd(PendingMove** pMoves, size_t maxMoves, size_t& curAmount, size_t maxAmount);
|
|
||||||
size_t Defrag_FindMovesFwd(PendingMove** pMoves, size_t maxMoves, size_t& curAmount, size_t maxAmount);
|
|
||||||
bool Defrag_CompletePendingMoves();
|
|
||||||
Index Defrag_Bwd_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressLimit);
|
|
||||||
Index Defrag_Fwd_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressLimit);
|
|
||||||
|
|
||||||
PendingMove* AllocPendingMove();
|
|
||||||
void FreePendingMove(PendingMove* pMove);
|
|
||||||
|
|
||||||
void CancelMove(Index srcChunkIdx, bool bIsContentNeeded);
|
|
||||||
void CancelMove_Locked(Index srcChunkIdx, bool bIsContentNeeded);
|
|
||||||
void Relocate(uint32 userMoveId, Index srcChunkIdx, Index dstChunkIdx);
|
|
||||||
|
|
||||||
void SyncMoveSegment(uint32 seg);
|
|
||||||
|
|
||||||
void RebuildFreeLists();
|
|
||||||
void ValidateAddressChain();
|
|
||||||
void ValidateFreeLists();
|
|
||||||
|
|
||||||
int BucketForSize(size_t sz) const
|
|
||||||
{
|
|
||||||
return sz > 0
|
|
||||||
? static_cast<int>(IntegerLog2(sz))
|
|
||||||
: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_isThreadSafe;
|
|
||||||
bool m_chunksAreFixed;
|
|
||||||
|
|
||||||
CryCriticalSection m_lock;
|
|
||||||
|
|
||||||
uint32 m_capacity;
|
|
||||||
uint32 m_available;
|
|
||||||
Index m_numAllocs;
|
|
||||||
|
|
||||||
uint16 m_minAlignment;
|
|
||||||
uint16 m_logMinAlignment;
|
|
||||||
|
|
||||||
Index m_freeBuckets[NumBuckets];
|
|
||||||
|
|
||||||
std::vector<SDefragAllocChunk> m_chunks;
|
|
||||||
std::vector<Index> m_unusedChunks;
|
|
||||||
PendingMoveVec m_pendingMoves;
|
|
||||||
SegmentVec m_segments;
|
|
||||||
|
|
||||||
uint32 m_nCancelledMoves;
|
|
||||||
|
|
||||||
Policy m_policy;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_DEFRAGALLOCATOR_H
|
|
||||||
@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "HMDCVars.h"
|
|
||||||
#include <HMDBus.h>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace AZ
|
|
||||||
{
|
|
||||||
namespace VR
|
|
||||||
{
|
|
||||||
|
|
||||||
void HMDCVars::OnHMDRecenter([[maybe_unused]] IConsoleCmdArgs* args)
|
|
||||||
{
|
|
||||||
EBUS_EVENT(AZ::VR::HMDDeviceRequestBus, RecenterPose);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HMDCVars::OnHMDTrackingLevelChange(IConsoleCmdArgs* args)
|
|
||||||
{
|
|
||||||
if (args->GetArgCount() != 2)
|
|
||||||
{
|
|
||||||
// First arg should be the command itself, second arg should be the requested tracking level.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the new tracking level.
|
|
||||||
int argVal = 0;
|
|
||||||
std::stringstream stream(args->GetArg(1));
|
|
||||||
stream >> argVal;
|
|
||||||
|
|
||||||
AZ::VR::HMDTrackingLevel level = static_cast<AZ::VR::HMDTrackingLevel>(argVal);
|
|
||||||
EBUS_EVENT(AZ::VR::HMDDeviceRequestBus, SetTrackingLevel, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HMDCVars::OnOutputToHMDChanged(ICVar* var)
|
|
||||||
{
|
|
||||||
// Set the necessary cvars for turning on/off output to an HMD.
|
|
||||||
ICVar* mode = gEnv->pConsole->GetCVar("r_StereoMode");
|
|
||||||
ICVar* output = gEnv->pConsole->GetCVar("r_StereoOutput");
|
|
||||||
ICVar* height = gEnv->pConsole->GetCVar("r_height");
|
|
||||||
ICVar* width = gEnv->pConsole->GetCVar("r_width");
|
|
||||||
|
|
||||||
if (!mode || !output || !height || !width)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool enable = (var->GetIVal() == 1);
|
|
||||||
if (enable)
|
|
||||||
{
|
|
||||||
// Auto-set the resolution.
|
|
||||||
{
|
|
||||||
const AZ::VR::HMDDeviceInfo* deviceInfo = nullptr;
|
|
||||||
EBUS_EVENT_RESULT(deviceInfo, AZ::VR::HMDDeviceRequestBus, GetDeviceInfo);
|
|
||||||
|
|
||||||
// If the device info exists then there is a VR device connected and working.
|
|
||||||
if (deviceInfo)
|
|
||||||
{
|
|
||||||
mode->Set(EStereoMode::STEREO_MODE_DUAL_RENDERING);
|
|
||||||
output->Set(EStereoOutput::STEREO_OUTPUT_HMD);
|
|
||||||
|
|
||||||
width->Set(static_cast<int>(deviceInfo->renderWidth));
|
|
||||||
height->Set(static_cast<int>(deviceInfo->renderHeight));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mode->Set(EStereoMode::STEREO_MODE_NO_STEREO);
|
|
||||||
output->Set(EStereoOutput::STEREO_OUTPUT_STANDARD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HMDCVars::OnHMDDebugInfo(ICVar* var)
|
|
||||||
{
|
|
||||||
bool enable = (var->GetIVal() == 1);
|
|
||||||
EBUS_EVENT(AZ::VR::HMDDebuggerRequestBus, EnableInfo, enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HMDCVars::OnHMDDebugCamera(ICVar* var)
|
|
||||||
{
|
|
||||||
bool enable = (var->GetIVal() == 1);
|
|
||||||
EBUS_EVENT(AZ::VR::HMDDebuggerRequestBus, EnableCamera, enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
int HMDCVars::hmd_social_screen = static_cast<int>(HMDSocialScreen::UndistortedLeftEye);
|
|
||||||
int HMDCVars::hmd_debug_info = 0;
|
|
||||||
int HMDCVars::hmd_debug_camera = 0;
|
|
||||||
|
|
||||||
} // namespace VR
|
|
||||||
} // namespace AZ
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <IConsole.h>
|
|
||||||
#include <ISystem.h>
|
|
||||||
|
|
||||||
namespace AZ
|
|
||||||
{
|
|
||||||
namespace VR
|
|
||||||
{
|
|
||||||
class HMDCVars
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
static int hmd_social_screen;
|
|
||||||
static int hmd_debug_info;
|
|
||||||
static int hmd_debug_camera;
|
|
||||||
|
|
||||||
static void Register()
|
|
||||||
{
|
|
||||||
REGISTER_CVAR2("hmd_social_screen", &hmd_social_screen, hmd_social_screen,
|
|
||||||
VF_NULL, "Selects the social screen mode: \n"
|
|
||||||
"-1- Off\n"
|
|
||||||
"0 - Undistorted left eye\n"
|
|
||||||
"1 - Undistorted right eye\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
REGISTER_INT_CB("hmd_debug_info", 0, VF_ALWAYSONCHANGE,
|
|
||||||
"Enable/disable HMD and VR controller debug info/rendering",
|
|
||||||
OnHMDDebugInfo);
|
|
||||||
|
|
||||||
REGISTER_INT_CB("hmd_debug_camera", 0, VF_ALWAYSONCHANGE,
|
|
||||||
"Enable/disable HMD debug camera",
|
|
||||||
OnHMDDebugCamera);
|
|
||||||
|
|
||||||
REGISTER_COMMAND("hmd_tracking_level", &OnHMDTrackingLevelChange,
|
|
||||||
VF_NULL, "Set the HMD center reference point.\n"
|
|
||||||
"0 - Camera (Actor's head)\n"
|
|
||||||
"1 - Actor's feet (floor)\n");
|
|
||||||
|
|
||||||
REGISTER_COMMAND("hmd_recenter_pose", &OnHMDRecenter,
|
|
||||||
VF_NULL, "Re-centers sensor orientation of the HMD.");
|
|
||||||
|
|
||||||
REGISTER_INT_CB("output_to_hmd", 0, VF_ALWAYSONCHANGE,
|
|
||||||
"Enable/disable output to any connected HMD (for VR)",
|
|
||||||
OnOutputToHMDChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static void OnHMDRecenter(IConsoleCmdArgs* args);
|
|
||||||
static void OnHMDTrackingLevelChange(IConsoleCmdArgs* args);
|
|
||||||
static void OnOutputToHMDChanged(ICVar* var);
|
|
||||||
static void OnHMDDebugInfo(ICVar* var);
|
|
||||||
static void OnHMDDebugCamera(ICVar* var);
|
|
||||||
};
|
|
||||||
} // namespace VR
|
|
||||||
} // namespace AZ
|
|
||||||
@ -1,325 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_MEMORYFRAGMENTATIONPROFILER_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_MEMORYFRAGMENTATIONPROFILER_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
// useful class to investigate memory fragmentation
|
|
||||||
// every time you call this from the console:
|
|
||||||
//
|
|
||||||
// #System.DumpMemoryCoverage()
|
|
||||||
//
|
|
||||||
// it adds a line to "MemoryCoverage.bmp" (generated the first time, there is a max line count)
|
|
||||||
// blue stripes mark some special positions (DLL positions)
|
|
||||||
|
|
||||||
// Dependencies: only CryLog()
|
|
||||||
|
|
||||||
|
|
||||||
#include <vector> // STL vector<>
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(WIN32) || defined(WIN64)
|
|
||||||
|
|
||||||
class CMemoryFragmentationProfiler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
// constructor - clean file
|
|
||||||
CMemoryFragmentationProfiler()
|
|
||||||
: m_dwLine(0xffffffff) // 0xffffffff means not initialized yet
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// call this if you want to add one line (on first call the file is generated)
|
|
||||||
void DumpMemoryCoverage()
|
|
||||||
{
|
|
||||||
if (m_dwLine == 0xffffffff)
|
|
||||||
{
|
|
||||||
Init();
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t nMinMemoryPerUnit = 4 * 1024; // down to a few KB
|
|
||||||
const size_t nUnitsPerLine = 1024 * 8; // amount of bits, should only occupy a few KB memory
|
|
||||||
|
|
||||||
const size_t nMaxMemoryPerUnit = 0x100000000 / nUnitsPerLine; // 4GB in total
|
|
||||||
|
|
||||||
static std::vector<bool> vCoverage;
|
|
||||||
|
|
||||||
vCoverage.clear();
|
|
||||||
vCoverage.resize(nUnitsPerLine, 0); // should occupy nUnitsPerLine/8 bytes (vector<bool> is specialized)
|
|
||||||
|
|
||||||
size_t nAvailableMem = 0, nUsedMem = 0;
|
|
||||||
|
|
||||||
const size_t nMallocOverhead = 24; // depends on used runtime (debug:32, release:24)
|
|
||||||
|
|
||||||
size_t nCurrentUnitSize = 256 * 1024 * 1024; // start with 256 MB blocks
|
|
||||||
|
|
||||||
void** pMemoryBlocks = 0; // linked list of memory blocks (to free them)
|
|
||||||
|
|
||||||
size_t nUnits = 0;
|
|
||||||
uint32 dwAllocCnt = 0, dwFreeCnt = 0;
|
|
||||||
|
|
||||||
while (nCurrentUnitSize >= nMinMemoryPerUnit)
|
|
||||||
{
|
|
||||||
size_t nLocalUnits = 0;
|
|
||||||
|
|
||||||
for (;; )
|
|
||||||
{
|
|
||||||
void** pMem = (void**)::malloc(nCurrentUnitSize - nMallocOverhead);
|
|
||||||
|
|
||||||
if (!pMem)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
++dwAllocCnt;
|
|
||||||
|
|
||||||
// update coverage (conservative)
|
|
||||||
{
|
|
||||||
size_t nStartUnit = ((size_t)pMem + nMaxMemoryPerUnit - 1) / (nMaxMemoryPerUnit);
|
|
||||||
size_t nEndUnit = ((size_t)pMem + nCurrentUnitSize) / (nMaxMemoryPerUnit);
|
|
||||||
|
|
||||||
if (nStartUnit > nUnitsPerLine)
|
|
||||||
{
|
|
||||||
nStartUnit = nUnitsPerLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nEndUnit > nUnitsPerLine)
|
|
||||||
{
|
|
||||||
nEndUnit = nUnitsPerLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = nStartUnit; i < nEndUnit; ++i)
|
|
||||||
{
|
|
||||||
vCoverage[i] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++nLocalUnits;
|
|
||||||
|
|
||||||
// insert in linked list
|
|
||||||
*pMem = pMemoryBlocks;
|
|
||||||
pMemoryBlocks = pMem;
|
|
||||||
}
|
|
||||||
|
|
||||||
nUnits += nLocalUnits;
|
|
||||||
nAvailableMem += nLocalUnits * nCurrentUnitSize;
|
|
||||||
|
|
||||||
nCurrentUnitSize /= 2;
|
|
||||||
nUnits *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// free all memory blocks allocated
|
|
||||||
while (pMemoryBlocks)
|
|
||||||
{
|
|
||||||
void* pNext = *pMemoryBlocks;
|
|
||||||
|
|
||||||
::free(pMemoryBlocks);
|
|
||||||
++dwFreeCnt;
|
|
||||||
|
|
||||||
pMemoryBlocks = (void**)pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// _heapmin();
|
|
||||||
|
|
||||||
CryLog("CMemoryFragmentationProfiler Y=%d, available memory=%d MB, used memory=%d MB",
|
|
||||||
m_dwLine, (nAvailableMem + 1024 * 1024 - 1) / (1024 * 1024), (nUsedMem + 1024 * 1024 - 1) / (1024 * 1024));
|
|
||||||
|
|
||||||
LogCoverage(vCoverage);
|
|
||||||
|
|
||||||
DumpToRAWCoverage(vCoverage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private: // ------------------------------------------------------------------
|
|
||||||
|
|
||||||
void Init()
|
|
||||||
{
|
|
||||||
FILE* out = nullptr;
|
|
||||||
azfopen(&out, "MemoryCoverage.bmp", "wb");
|
|
||||||
|
|
||||||
if (out)
|
|
||||||
{
|
|
||||||
BITMAPFILEHEADER pHeader;
|
|
||||||
BITMAPINFOHEADER pInfoHeader;
|
|
||||||
|
|
||||||
memset(&pHeader, 0, sizeof(BITMAPFILEHEADER));
|
|
||||||
memset(&pInfoHeader, 0, sizeof(BITMAPINFOHEADER));
|
|
||||||
|
|
||||||
pHeader.bfType = 0x4D42;
|
|
||||||
pHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + m_nPixelsPerLine * m_nLineCount * 3;
|
|
||||||
pHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
|
||||||
|
|
||||||
pInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
||||||
pInfoHeader.biWidth = m_nPixelsPerLine;
|
|
||||||
pInfoHeader.biHeight = m_nLineCount;
|
|
||||||
pInfoHeader.biPlanes = 1;
|
|
||||||
pInfoHeader.biBitCount = 24;
|
|
||||||
pInfoHeader.biCompression = 0;
|
|
||||||
pInfoHeader.biSizeImage = m_nPixelsPerLine * m_nLineCount;
|
|
||||||
|
|
||||||
fwrite(&pHeader, 1, sizeof(BITMAPFILEHEADER), out);
|
|
||||||
fwrite(&pInfoHeader, 1, sizeof(BITMAPINFOHEADER), out);
|
|
||||||
|
|
||||||
for (int y = 0; y < m_nLineCount; y++) // amount of lines
|
|
||||||
{
|
|
||||||
for (int x = 0; x < m_nPixelsPerLine; x++)
|
|
||||||
{
|
|
||||||
size_t nAddress = x * (0x100000000 / m_nPixelsPerLine);
|
|
||||||
|
|
||||||
if (nAddress == 0x30000000
|
|
||||||
|| nAddress == 0x30500000
|
|
||||||
|| nAddress == 0x31000000
|
|
||||||
|| nAddress == 0x31500000
|
|
||||||
|| nAddress == 0x32000000
|
|
||||||
|| nAddress == 0x32500000
|
|
||||||
|| nAddress == 0x33500000
|
|
||||||
|| nAddress == 0x34000000
|
|
||||||
|| nAddress == 0x35000000
|
|
||||||
|| nAddress == 0x35500000
|
|
||||||
|| nAddress == 0x36000000
|
|
||||||
|| nAddress == 0x36500000
|
|
||||||
|| nAddress == 0x38000000
|
|
||||||
|| nAddress == 0x39000000)
|
|
||||||
{
|
|
||||||
putc((unsigned char)100, out); // blue DLL start
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
putc((unsigned char)0, out); // black
|
|
||||||
}
|
|
||||||
putc((unsigned char)0, out);
|
|
||||||
putc((unsigned char)0, out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(out);
|
|
||||||
m_dwLine = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogCoverage(std::vector<bool>& vCov)
|
|
||||||
{
|
|
||||||
const size_t nCharPerLine = 128; // readable amount
|
|
||||||
|
|
||||||
char szResult[nCharPerLine + 1], * pCursor = szResult;
|
|
||||||
|
|
||||||
szResult[nCharPerLine] = 0; // zero termination
|
|
||||||
|
|
||||||
size_t nSize = vCov.size();
|
|
||||||
size_t nUnitsPerChar = nSize / nCharPerLine;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < nSize; )
|
|
||||||
{
|
|
||||||
unsigned int nLocalCov = 0;
|
|
||||||
|
|
||||||
for (size_t e = 0; e < nUnitsPerChar; ++e, ++i)
|
|
||||||
{
|
|
||||||
if (vCov[i])
|
|
||||||
{
|
|
||||||
++nLocalCov;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nLocalCov == 0)
|
|
||||||
{
|
|
||||||
*pCursor++ = '#'; // occupied
|
|
||||||
}
|
|
||||||
else if (nLocalCov == nUnitsPerChar)
|
|
||||||
{
|
|
||||||
*pCursor++ = '.'; // free
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*pCursor++ = '+'; // partly
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CryLog(" Coverage=%s", szResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DumpToRAWCoverage(std::vector<bool>& vCov)
|
|
||||||
{
|
|
||||||
FILE* out = nullptr;
|
|
||||||
azfopen(&out, "MemoryCoverage.bmp", "rb+");
|
|
||||||
|
|
||||||
if (!out)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fseek(out, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 3 * (m_nLineCount - 1 - m_dwLine) * m_nPixelsPerLine, SEEK_SET) != 0)
|
|
||||||
{
|
|
||||||
fclose(out);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t nSize = vCov.size();
|
|
||||||
size_t nUnitsPerChar = nSize / m_nPixelsPerLine;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < nSize; )
|
|
||||||
{
|
|
||||||
unsigned int nLocalCov = 0;
|
|
||||||
|
|
||||||
for (size_t e = 0; e < nUnitsPerChar; ++e, ++i)
|
|
||||||
{
|
|
||||||
if (vCov[i])
|
|
||||||
{
|
|
||||||
++nLocalCov;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Val = 256 - (256 * nLocalCov) / nUnitsPerChar;
|
|
||||||
|
|
||||||
if (Val > 0)
|
|
||||||
{
|
|
||||||
Val = 127 + Val / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
putc((unsigned char)Val, out);
|
|
||||||
putc((unsigned char)Val, out);
|
|
||||||
putc((unsigned char)Val, out); // grey
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(out);
|
|
||||||
|
|
||||||
++m_dwLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int m_dwLine; // [0..m_nLineCount-1], m_nLineCount means bitmap is full, 0xffffffff means not initialized yet
|
|
||||||
static const size_t m_nPixelsPerLine = 1024; // bitmap width
|
|
||||||
static const size_t m_nLineCount = 128; //
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#else // defined(WIN32) || defined(WIN64)
|
|
||||||
|
|
||||||
|
|
||||||
class CMemoryFragmentationProfiler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void DumpMemoryCoverage() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // defined(WIN32) || defined(WIN64)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_MEMORYFRAGMENTATIONPROFILER_H
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,160 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "DrawContext.h"
|
|
||||||
#include <ISystem.h>
|
|
||||||
#include <IRenderer.h>
|
|
||||||
#include <IRenderAuxGeom.h>
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
CDrawContext::CDrawContext(SMetrics* pMetrics)
|
|
||||||
{
|
|
||||||
m_currentStackLevel = 0;
|
|
||||||
m_x = 0;
|
|
||||||
m_y = 0;
|
|
||||||
m_pMetrics = pMetrics;
|
|
||||||
m_color = ColorB(0, 0, 0, 0);
|
|
||||||
m_defaultZ = 0.0f;
|
|
||||||
m_pAuxRender = gEnv->pRenderer->GetIRenderAuxGeom();
|
|
||||||
|
|
||||||
m_frameWidth = (float)gEnv->pRenderer->GetWidth();
|
|
||||||
m_frameHeight = (float)gEnv->pRenderer->GetHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::SetColor(ColorB color)
|
|
||||||
{
|
|
||||||
m_color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::DrawLine(float x0, float y0, float x1, float y1, float thickness /*= 1.0f */)
|
|
||||||
{
|
|
||||||
m_pAuxRender->DrawLine(Vec3(m_x + x0, m_y + y0, m_defaultZ), m_color, Vec3(m_x + x1, m_y + y1, m_defaultZ), m_color, thickness);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::DrawTriangle(float x0, float y0, float x1, float y1, float x2, float y2)
|
|
||||||
{
|
|
||||||
m_pAuxRender->DrawTriangle(Vec3(m_x + x0, m_y + y0, m_defaultZ), m_color, Vec3(m_x + x1, m_y + y1, m_defaultZ), m_color, Vec3(m_x + x2, m_y + y2, m_defaultZ), m_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::DrawRect(const Rect& rc)
|
|
||||||
{
|
|
||||||
m_pAuxRender->DrawTriangle(Vec3(m_x + rc.left, m_y + rc.top, m_defaultZ), m_color, Vec3(m_x + rc.left, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.top, m_defaultZ), m_color);
|
|
||||||
m_pAuxRender->DrawTriangle(Vec3(m_x + rc.left, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.top, m_defaultZ), m_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::DrawFrame(const Rect& rc, ColorB lineColor, ColorB solidColor, float thickness)
|
|
||||||
{
|
|
||||||
ColorB prevColor = m_color;
|
|
||||||
|
|
||||||
SetColor(solidColor);
|
|
||||||
DrawRect(rc);
|
|
||||||
|
|
||||||
SetColor(lineColor);
|
|
||||||
|
|
||||||
uint32 curFlags = m_pAuxRender->GetRenderFlags().m_renderFlags;
|
|
||||||
m_pAuxRender->SetRenderFlags(curFlags | e_DrawInFrontOn);
|
|
||||||
DrawLine(rc.left, rc.top, rc.right, rc.top, thickness);
|
|
||||||
DrawLine(rc.right, rc.top, rc.right, rc.bottom, thickness);
|
|
||||||
DrawLine(rc.left, rc.top, rc.left, rc.bottom, thickness);
|
|
||||||
DrawLine(rc.left, rc.bottom, rc.right, rc.bottom, thickness);
|
|
||||||
m_pAuxRender->SetRenderFlags(curFlags);
|
|
||||||
|
|
||||||
m_color = prevColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::StartDrawing()
|
|
||||||
{
|
|
||||||
uint32 width = gEnv->pRenderer->GetWidth();
|
|
||||||
uint32 height = gEnv->pRenderer->GetHeight();
|
|
||||||
|
|
||||||
gEnv->pRenderer->Set2DMode(width, height, m_backupSceneMatrices);
|
|
||||||
|
|
||||||
m_prevRenderFlags = m_pAuxRender->GetRenderFlags().m_renderFlags;
|
|
||||||
m_pAuxRender->SetRenderFlags(e_Mode3D | e_AlphaBlended | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOff);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::StopDrawing()
|
|
||||||
{
|
|
||||||
// Restore old flags that where set before our draw context.
|
|
||||||
m_pAuxRender->SetRenderFlags(m_prevRenderFlags);
|
|
||||||
|
|
||||||
gEnv->pRenderer->Unset2DMode(m_backupSceneMatrices);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::DrawString(float x, float y, float font_size, ETextAlign align, const char* format, ...)
|
|
||||||
{
|
|
||||||
//text will be off screen
|
|
||||||
if (y > m_frameHeight || x > m_frameWidth)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
SDrawTextInfo ti;
|
|
||||||
ti.xscale = ti.yscale = font_size / 12.0f; // font size in pixels to text scale.
|
|
||||||
|
|
||||||
ti.flags = eDrawText_Monospace | eDrawText_2D | eDrawText_FixedSize | eDrawText_IgnoreOverscan;
|
|
||||||
if (align == eTextAlign_Left)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (align == eTextAlign_Right)
|
|
||||||
{
|
|
||||||
ti.flags |= eDrawText_Right;
|
|
||||||
}
|
|
||||||
else if (align == eTextAlign_Center)
|
|
||||||
{
|
|
||||||
ti.flags |= eDrawText_Center;
|
|
||||||
}
|
|
||||||
ti.color[0] = (float)m_color.r / 255.0f;
|
|
||||||
ti.color[1] = (float)m_color.g / 255.0f;
|
|
||||||
ti.color[2] = (float)m_color.b / 255.0f;
|
|
||||||
ti.color[3] = (float)m_color.a / 255.0f;
|
|
||||||
gEnv->pRenderer->DrawTextQueued(Vec3(m_x + x, m_y + y, m_defaultZ), ti, format, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::PushClientRect(const Rect& rc)
|
|
||||||
{
|
|
||||||
m_currentStackLevel++;
|
|
||||||
assert(m_currentStackLevel < MAX_ORIGIN_STACK);
|
|
||||||
m_clientRectStack[m_currentStackLevel] = rc;
|
|
||||||
m_x += rc.left;
|
|
||||||
m_y += rc.top;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CDrawContext::PopClientRect()
|
|
||||||
{
|
|
||||||
if (m_currentStackLevel > 0)
|
|
||||||
{
|
|
||||||
Rect& rc = m_clientRectStack[m_currentStackLevel];
|
|
||||||
m_x -= rc.left;
|
|
||||||
m_y -= rc.top;
|
|
||||||
|
|
||||||
m_currentStackLevel--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MINIGUI_END
|
|
||||||
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : DrawContext helper class for MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "ICryMiniGUI.h"
|
|
||||||
#include <Cry_Color.h>
|
|
||||||
|
|
||||||
struct IRenderAuxGeom;
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
enum ETextAlign
|
|
||||||
{
|
|
||||||
eTextAlign_Left,
|
|
||||||
eTextAlign_Right,
|
|
||||||
eTextAlign_Center
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Context of MiniGUI drawing.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
class CDrawContext
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CDrawContext(SMetrics* pMetrics);
|
|
||||||
|
|
||||||
// Must be called before any drawing happens
|
|
||||||
void StartDrawing();
|
|
||||||
// Must be called after all drawing have been complete.
|
|
||||||
void StopDrawing();
|
|
||||||
|
|
||||||
void PushClientRect(const Rect& rc);
|
|
||||||
void PopClientRect();
|
|
||||||
|
|
||||||
SMetrics& Metrics() { return *m_pMetrics; }
|
|
||||||
void SetColor(ColorB color);
|
|
||||||
|
|
||||||
void DrawLine(float x0, float y0, float x1, float y1, float thickness = 1.0f);
|
|
||||||
void DrawTriangle(float x0, float y0, float x1, float y1, float x2, float y2);
|
|
||||||
void DrawRect(const Rect& rc);
|
|
||||||
void DrawFrame(const Rect& rc, ColorB lineColor, ColorB solidColor, float thickness = 1.0f);
|
|
||||||
|
|
||||||
void DrawString(float x, float y, float font_size, ETextAlign align, const char* format, ...);
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SMetrics* m_pMetrics;
|
|
||||||
|
|
||||||
ColorB m_color;
|
|
||||||
float m_defaultZ;
|
|
||||||
IRenderAuxGeom* m_pAuxRender;
|
|
||||||
uint32 m_prevRenderFlags;
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
MAX_ORIGIN_STACK = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
int m_currentStackLevel;
|
|
||||||
float m_x, m_y; // Reference X,Y positions
|
|
||||||
Rect m_clientRectStack[MAX_ORIGIN_STACK];
|
|
||||||
|
|
||||||
float m_frameWidth;
|
|
||||||
float m_frameHeight;
|
|
||||||
|
|
||||||
private:
|
|
||||||
TransformationMatrices m_backupSceneMatrices;
|
|
||||||
};
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H
|
|
||||||
@ -1,316 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Button implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "MiniButton.h"
|
|
||||||
#include "DrawContext.h"
|
|
||||||
#include <ISystem.h>
|
|
||||||
#include <IConsole.h>
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
|
|
||||||
CMiniButton::CMiniButton()
|
|
||||||
{
|
|
||||||
m_pCVar = NULL;
|
|
||||||
m_fCVarValue[0] = 0;
|
|
||||||
m_fCVarValue[1] = 1;
|
|
||||||
m_saveStateOn = false;
|
|
||||||
m_clickCallback = NULL;
|
|
||||||
m_pCallbackData = NULL;
|
|
||||||
m_pConnectedCtrl = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniButton::Reset()
|
|
||||||
{
|
|
||||||
/*if (m_pCVar)
|
|
||||||
{
|
|
||||||
pCVar->Set( m_fCVarValue[0] );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*if(m_pConnectedCtrl)
|
|
||||||
{
|
|
||||||
m_pConnectedCtrl->SetVisible(false);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
clear_flag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniButton::SaveState()
|
|
||||||
{
|
|
||||||
if (is_flag(eCtrl_Checked))
|
|
||||||
{
|
|
||||||
if (m_pConnectedCtrl && m_pConnectedCtrl->CheckFlag(eCtrl_Hidden))
|
|
||||||
{
|
|
||||||
m_saveStateOn = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_saveStateOn = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_saveStateOn = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniButton::RestoreState()
|
|
||||||
{
|
|
||||||
if (m_pCVar)
|
|
||||||
{
|
|
||||||
if (m_pCVar->GetFVal() == m_fCVarValue[1])
|
|
||||||
{
|
|
||||||
set_flag(eCtrl_Checked);
|
|
||||||
|
|
||||||
|
|
||||||
//Restoring CVars has caused a few issues, especially when the user is changing
|
|
||||||
//CVars through the console while perfHud is active, removing for now
|
|
||||||
//pCVar->Set( m_saveStateOn ? m_fCVarValue[1] : m_fCVarValue[0] );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
clear_flag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//connected controls (tables / info boxes etc) now look after themselves
|
|
||||||
/*if(m_pConnectedCtrl)
|
|
||||||
{
|
|
||||||
m_pConnectedCtrl->SetVisible(m_saveStateOn);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (CheckFlag(eCtrl_CheckButton))
|
|
||||||
{
|
|
||||||
if (m_saveStateOn)
|
|
||||||
{
|
|
||||||
set_flag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
clear_flag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniButton::OnPaint(CDrawContext& dc)
|
|
||||||
{
|
|
||||||
ColorB bkgColor = dc.Metrics().clrBackground;
|
|
||||||
|
|
||||||
if (is_flag(eCtrl_Highlight))
|
|
||||||
{
|
|
||||||
bkgColor = dc.Metrics().clrBackgroundHighlight;
|
|
||||||
}
|
|
||||||
else if (is_flag(eCtrl_Checked))
|
|
||||||
{
|
|
||||||
//if connected control has been hidden, this button should not be checked
|
|
||||||
if (m_pConnectedCtrl && m_pConnectedCtrl->CheckFlag(eCtrl_Hidden))
|
|
||||||
{
|
|
||||||
clear_flag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bkgColor = dc.Metrics().clrBackgroundSelected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float borderThickness = 1.0f;
|
|
||||||
|
|
||||||
if (is_flag(eCtrl_Focus))
|
|
||||||
{
|
|
||||||
borderThickness = 3.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorB borderCol = dc.Metrics().clrFrameBorder;
|
|
||||||
|
|
||||||
if (!m_pGUI->InFocus())
|
|
||||||
{
|
|
||||||
borderCol = dc.Metrics().clrFrameBorderOutOfFocus;
|
|
||||||
bkgColor.a = dc.Metrics().outOfFocusAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.DrawFrame(m_rect, borderCol, bkgColor, borderThickness);
|
|
||||||
|
|
||||||
ColorB textColor = dc.Metrics().clrText;
|
|
||||||
|
|
||||||
if (is_flag(eCtrl_Checked | eCtrl_Highlight))
|
|
||||||
{
|
|
||||||
textColor = dc.Metrics().clrTextSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.SetColor(textColor);
|
|
||||||
|
|
||||||
ETextAlign align;
|
|
||||||
float startX;
|
|
||||||
|
|
||||||
if (is_flag(eCtrl_TextAlignCentre))
|
|
||||||
{
|
|
||||||
startX = (m_rect.left + m_rect.right) / 2.f;
|
|
||||||
align = eTextAlign_Center;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
startX = m_rect.left + 5.f;
|
|
||||||
align = eTextAlign_Left;
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.DrawString(startX, m_rect.top, dc.Metrics().fTitleSize, align, GetTitle());
|
|
||||||
|
|
||||||
//Check not very obvious
|
|
||||||
#if 0
|
|
||||||
if (is_flag(eCtrl_Checked))
|
|
||||||
{
|
|
||||||
// Draw checked mark.
|
|
||||||
float checkX = m_rect.left + 4;
|
|
||||||
float checkY = (m_rect.bottom + m_rect.top) * 0.5f;
|
|
||||||
dc.SetColor(dc.Metrics().clrChecked);
|
|
||||||
dc.DrawLine(checkX, checkY, checkX + 3, checkY + 3);
|
|
||||||
dc.DrawLine(checkX + 3, checkY + 3, checkX + 7, checkY - 6);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniButton::SetRect(const Rect& rc)
|
|
||||||
{
|
|
||||||
Rect newrc = rc;
|
|
||||||
newrc.bottom = newrc.top + m_pGUI->Metrics().fTitleSize + 2;
|
|
||||||
CMiniCtrl::SetRect(newrc);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniButton::OnEvent(float x, float y, EMiniCtrlEvent event)
|
|
||||||
{
|
|
||||||
switch (event)
|
|
||||||
{
|
|
||||||
case eCtrlEvent_LButtonDown:
|
|
||||||
{
|
|
||||||
SCommand cmd;
|
|
||||||
|
|
||||||
if (CheckFlag(eCtrl_CheckButton))
|
|
||||||
{
|
|
||||||
if (!CheckFlag(eCtrl_Checked))
|
|
||||||
{
|
|
||||||
cmd.command = eCommand_ButtonChecked;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cmd.command = eCommand_ButtonUnchecked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cmd.command = eCommand_ButtonPress;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.nCtrlID = GetId();
|
|
||||||
cmd.pCtrl = this;
|
|
||||||
GetGUI()->OnCommand(cmd);
|
|
||||||
|
|
||||||
if (CheckFlag(eCtrl_CheckButton))
|
|
||||||
{
|
|
||||||
bool bOn = false;
|
|
||||||
|
|
||||||
if (CheckFlag(eCtrl_Checked))
|
|
||||||
{
|
|
||||||
bOn = false;
|
|
||||||
ClearFlag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bOn = true;
|
|
||||||
SetFlag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_pCVar)
|
|
||||||
{
|
|
||||||
m_pCVar->Set(m_fCVarValue[bOn ? 1 : 0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_pConnectedCtrl)
|
|
||||||
{
|
|
||||||
m_pConnectedCtrl->SetVisible(bOn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//cross button behavior
|
|
||||||
if (m_pConnectedCtrl)
|
|
||||||
{
|
|
||||||
m_pConnectedCtrl->SetVisible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_clickCallback)
|
|
||||||
{
|
|
||||||
m_clickCallback(m_pCallbackData, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eCtrlEvent_MouseOff:
|
|
||||||
{
|
|
||||||
if (m_pParent)
|
|
||||||
{
|
|
||||||
m_pParent->OnEvent(x, y, eCtrlEvent_MouseOff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
bool CMiniButton::SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue)
|
|
||||||
{
|
|
||||||
m_pCVar = GetISystem()->GetIConsole()->GetCVar(sCVarName);
|
|
||||||
|
|
||||||
if (!m_pCVar)
|
|
||||||
{
|
|
||||||
CryLogAlways("failed to find CVar: %s\n", sCVarName);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_fCVarValue[0] = fOffValue;
|
|
||||||
m_fCVarValue[1] = fOnValue;
|
|
||||||
|
|
||||||
if (m_pCVar && m_pCVar->GetFVal() == fOnValue)
|
|
||||||
{
|
|
||||||
set_flag(eCtrl_Checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
bool CMiniButton::SetClickCallback(ClickCallback callback, void* pCallbackData)
|
|
||||||
{
|
|
||||||
m_clickCallback = callback;
|
|
||||||
m_pCallbackData = pCallbackData;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
bool CMiniButton::SetConnectedCtrl(IMiniCtrl* pConnectedCtrl)
|
|
||||||
{
|
|
||||||
m_pConnectedCtrl = pConnectedCtrl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Button implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "MiniGUI.h"
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Root window all other controls derive from
|
|
||||||
class CMiniButton
|
|
||||||
: public CMiniCtrl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMiniButton();
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMiniCtrl interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual EMiniCtrlType GetType() const { return eCtrlType_Button; }
|
|
||||||
virtual void SetRect(const Rect& rc);
|
|
||||||
virtual void OnPaint(CDrawContext& dc);
|
|
||||||
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void SaveState();
|
|
||||||
virtual void RestoreState();
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
virtual bool SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue);
|
|
||||||
virtual bool SetClickCallback(ClickCallback callback, void* pCallbackData);
|
|
||||||
virtual bool SetConnectedCtrl(IMiniCtrl* pConnectedCtrl);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ICVar* m_pCVar;
|
|
||||||
float m_fCVarValue[2];
|
|
||||||
ClickCallback m_clickCallback;
|
|
||||||
void* m_pCallbackData;
|
|
||||||
IMiniCtrl* m_pConnectedCtrl;
|
|
||||||
};
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H
|
|
||||||
@ -1,862 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Implementation of the MiniGUI class
|
|
||||||
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "MiniGUI.h"
|
|
||||||
#include "DrawContext.h"
|
|
||||||
|
|
||||||
#include "MiniButton.h"
|
|
||||||
#include "MiniMenu.h"
|
|
||||||
#include "MiniInfoBox.h"
|
|
||||||
#include "MiniTable.h"
|
|
||||||
|
|
||||||
#include <ISystem.h>
|
|
||||||
#include <IRenderer.h>
|
|
||||||
|
|
||||||
#include <LyShine/Bus/UiCursorBus.h>
|
|
||||||
#include <AzFramework/Input/Devices/Gamepad/InputDeviceGamepad.h>
|
|
||||||
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
|
|
||||||
|
|
||||||
namespace minigui
|
|
||||||
{
|
|
||||||
CRYREGISTER_SINGLETON_CLASS(CMiniGUI)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::InitMetrics()
|
|
||||||
{
|
|
||||||
m_metrics.clrText = ColorB(255, 255, 255, 255);
|
|
||||||
m_metrics.clrTextSelected = ColorB(0, 255, 0, 255);
|
|
||||||
m_metrics.fTextSize = 12.0f;
|
|
||||||
|
|
||||||
m_metrics.clrTitle = ColorB(255, 255, 255, 255);
|
|
||||||
|
|
||||||
m_metrics.fTitleSize = 14.0f;
|
|
||||||
|
|
||||||
const int backgroundAlpha = 255;
|
|
||||||
|
|
||||||
m_metrics.clrBackground = ColorB(20, 20, 20, backgroundAlpha);
|
|
||||||
m_metrics.clrBackgroundHighlight = ColorB(10, 10, 150, backgroundAlpha);
|
|
||||||
m_metrics.clrBackgroundSelected = ColorB(10, 120, 10, backgroundAlpha);
|
|
||||||
|
|
||||||
m_metrics.clrFrameBorder = ColorB(255, 0, 0, 255);
|
|
||||||
m_metrics.clrFrameBorderHighlight = ColorB(255, 255, 0, 255);
|
|
||||||
m_metrics.clrFrameBorderOutOfFocus = ColorB(0, 0, 0, 255);
|
|
||||||
|
|
||||||
m_metrics.clrChecked = ColorB(0, 0, 0, 255);
|
|
||||||
m_metrics.outOfFocusAlpha = 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CMiniCtrlRoot
|
|
||||||
: public CMiniCtrl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMiniCtrlRoot() {};
|
|
||||||
virtual EMiniCtrlType GetType() const { return eCtrlType_Unknown; };
|
|
||||||
virtual void OnPaint([[maybe_unused]] class CDrawContext& dc) {};
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
CMiniGUI::CMiniGUI()
|
|
||||||
: m_enabled(false)
|
|
||||||
, m_inFocus(true)
|
|
||||||
, m_pDPadMenu(NULL)
|
|
||||||
, m_pMovingCtrl(NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
CMiniGUI::~CMiniGUI()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::Init()
|
|
||||||
{
|
|
||||||
m_pEventListener = NULL;
|
|
||||||
InitMetrics();
|
|
||||||
|
|
||||||
AzFramework::InputChannelEventListener::Connect();
|
|
||||||
|
|
||||||
m_pRootCtrl = new CMiniCtrlRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::Reset()
|
|
||||||
{
|
|
||||||
m_pRootCtrl->Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::SaveState()
|
|
||||||
{
|
|
||||||
m_pRootCtrl->SaveState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::RestoreState()
|
|
||||||
{
|
|
||||||
m_pRootCtrl->RestoreState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::SetEnabled(bool status)
|
|
||||||
{
|
|
||||||
m_enabled = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::SetInFocus(bool status)
|
|
||||||
{
|
|
||||||
if (status)
|
|
||||||
{
|
|
||||||
m_inFocus = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CloseDPadMenu();
|
|
||||||
m_inFocus = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::Done()
|
|
||||||
{
|
|
||||||
AzFramework::InputChannelEventListener::Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::Draw()
|
|
||||||
{
|
|
||||||
FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SYSTEM, g_bProfilerEnabled);
|
|
||||||
|
|
||||||
// When console opened hide MiniGui
|
|
||||||
bool bConsoleOpened = gEnv->pConsole->IsOpened();
|
|
||||||
if (m_enabled && !bConsoleOpened)
|
|
||||||
{
|
|
||||||
ProcessInput();
|
|
||||||
|
|
||||||
CDrawContext dc(&m_metrics);
|
|
||||||
dc.StartDrawing();
|
|
||||||
{
|
|
||||||
// Draw all controls.
|
|
||||||
m_pRootCtrl->DrawCtrl(dc);
|
|
||||||
}
|
|
||||||
dc.StopDrawing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::ProcessInput()
|
|
||||||
{
|
|
||||||
//check we are not in digital selection mode
|
|
||||||
if (!m_pDPadMenu)
|
|
||||||
{
|
|
||||||
float mx(0), my(0);
|
|
||||||
AZ::Vector2 systemCursorPositionNormalized = AZ::Vector2::CreateZero();
|
|
||||||
AzFramework::InputSystemCursorRequestBus::EventResult(systemCursorPositionNormalized,
|
|
||||||
AzFramework::InputDeviceMouse::Id,
|
|
||||||
&AzFramework::InputSystemCursorRequests::GetSystemCursorPositionNormalized);
|
|
||||||
mx = systemCursorPositionNormalized.GetX() * gEnv->pRenderer->GetWidth();
|
|
||||||
my = systemCursorPositionNormalized.GetY() * gEnv->pRenderer->GetHeight();
|
|
||||||
|
|
||||||
//update moving control
|
|
||||||
if (m_pMovingCtrl)
|
|
||||||
{
|
|
||||||
m_pMovingCtrl->Move(mx, my);
|
|
||||||
}
|
|
||||||
|
|
||||||
IMiniCtrl* pCtrl = GetCtrlFromPoint(mx, my);
|
|
||||||
if (pCtrl)
|
|
||||||
{
|
|
||||||
SetHighlight(pCtrl, true, mx, my);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetHighlight(m_highlightedCtrl, false, mx, my);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
IMiniCtrl* CMiniGUI::GetCtrlFromPoint(float x, float y) const
|
|
||||||
{
|
|
||||||
// Draw all controls.
|
|
||||||
return m_pRootCtrl->GetCtrlFromPoint(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::SetHighlight(IMiniCtrl* pCtrl, bool bEnable, float x, float y)
|
|
||||||
{
|
|
||||||
if (pCtrl)
|
|
||||||
{
|
|
||||||
if (m_highlightedCtrl && m_highlightedCtrl != pCtrl)
|
|
||||||
{
|
|
||||||
m_highlightedCtrl->OnEvent(x, y, eCtrlEvent_MouseOff);
|
|
||||||
m_highlightedCtrl->ClearFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bEnable)
|
|
||||||
{
|
|
||||||
pCtrl->OnEvent(x, y, eCtrlEvent_MouseOver);
|
|
||||||
pCtrl->SetFlag(eCtrl_Highlight);
|
|
||||||
|
|
||||||
m_highlightedCtrl = pCtrl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pCtrl->OnEvent(x, y, eCtrlEvent_MouseOff);
|
|
||||||
pCtrl->ClearFlag(eCtrl_Highlight);
|
|
||||||
m_highlightedCtrl = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(bEnable == false);
|
|
||||||
|
|
||||||
if (m_highlightedCtrl)
|
|
||||||
{
|
|
||||||
m_highlightedCtrl->OnEvent(x, y, eCtrlEvent_MouseOff);
|
|
||||||
m_highlightedCtrl->ClearFlag(eCtrl_Highlight);
|
|
||||||
m_highlightedCtrl = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::SetFocus(IMiniCtrl* pCtrl, bool bEnable)
|
|
||||||
{
|
|
||||||
if (m_focusCtrl)
|
|
||||||
{
|
|
||||||
m_focusCtrl->ClearFlag(eCtrl_Focus);
|
|
||||||
}
|
|
||||||
m_focusCtrl = pCtrl;
|
|
||||||
if (m_focusCtrl)
|
|
||||||
{
|
|
||||||
if (bEnable)
|
|
||||||
{
|
|
||||||
m_focusCtrl->SetFlag(eCtrl_Focus);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_focusCtrl->ClearFlag(eCtrl_Focus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
SMetrics& CMiniGUI::Metrics()
|
|
||||||
{
|
|
||||||
return m_metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
IMiniCtrl* CMiniGUI::CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title)
|
|
||||||
{
|
|
||||||
CMiniCtrl* pCtrl = 0;
|
|
||||||
// Test code.
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case eCtrlType_Button:
|
|
||||||
pCtrl = new CMiniButton;
|
|
||||||
break;
|
|
||||||
case eCtrlType_Menu:
|
|
||||||
pCtrl = new CMiniMenu;
|
|
||||||
break;
|
|
||||||
case eCtrlType_InfoBox:
|
|
||||||
pCtrl = new CMiniInfoBox;
|
|
||||||
break;
|
|
||||||
case eCtrlType_Table:
|
|
||||||
pCtrl = new CMiniTable;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(0 && "Unknown MiniGUI control type");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
if (pCtrl)
|
|
||||||
{
|
|
||||||
pCtrl->SetGUI(this);
|
|
||||||
pCtrl->SetFlag(nCtrlFlags);
|
|
||||||
pCtrl->SetTitle(title);
|
|
||||||
pCtrl->SetRect(rc);
|
|
||||||
pCtrl->SetId(nCtrlID);
|
|
||||||
|
|
||||||
if (pCtrl->CheckFlag(eCtrl_AutoResize))
|
|
||||||
{
|
|
||||||
pCtrl->AutoResize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCtrl->CheckFlag(eCtrl_CloseButton))
|
|
||||||
{
|
|
||||||
pCtrl->CreateCloseButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pParentCtrl)
|
|
||||||
{
|
|
||||||
pParentCtrl->AddSubCtrl(pCtrl);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_pRootCtrl->AddSubCtrl(pCtrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == eCtrlType_Menu && pParentCtrl == NULL)
|
|
||||||
{
|
|
||||||
m_rootMenus.push_back(pCtrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pCtrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::OnCommand(SCommand& cmd)
|
|
||||||
{
|
|
||||||
if (m_pEventListener)
|
|
||||||
{
|
|
||||||
m_pEventListener->OnCommand(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::OnMouseInputEvent(const AzFramework::InputChannel& inputChannel)
|
|
||||||
{
|
|
||||||
if (!m_inFocus || !m_enabled)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AzFramework::InputChannel::PositionData2D* positionData2D = inputChannel.GetCustomData<AzFramework::InputChannel::PositionData2D>();
|
|
||||||
if (!positionData2D)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const float mx = positionData2D->m_normalizedPosition.GetX() * gEnv->pRenderer->GetWidth();
|
|
||||||
const float my = positionData2D->m_normalizedPosition.GetY() * gEnv->pRenderer->GetHeight();
|
|
||||||
IMiniCtrl* pCtrl = GetCtrlFromPoint(mx, my);
|
|
||||||
if (pCtrl)
|
|
||||||
{
|
|
||||||
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
|
|
||||||
if (channelId == AzFramework::InputDeviceMouse::Button::Left)
|
|
||||||
{
|
|
||||||
if (inputChannel.IsStateBegan())
|
|
||||||
{
|
|
||||||
pCtrl->OnEvent(mx, my, eCtrlEvent_LButtonDown);
|
|
||||||
}
|
|
||||||
else if (inputChannel.IsStateEnded())
|
|
||||||
{
|
|
||||||
pCtrl->OnEvent(mx, my, eCtrlEvent_LButtonUp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniGUI::SetDPadMenu(IMiniCtrl* pMenu)
|
|
||||||
{
|
|
||||||
m_pDPadMenu = (CMiniMenu*)pMenu;
|
|
||||||
UiCursorBus::Broadcast(&UiCursorInterface::DecrementVisibleCounter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniGUI::CloseDPadMenu()
|
|
||||||
{
|
|
||||||
if (m_pDPadMenu)
|
|
||||||
{
|
|
||||||
CMiniMenu* closeMenu = m_pDPadMenu;
|
|
||||||
|
|
||||||
//close menu and all parent menus
|
|
||||||
do
|
|
||||||
{
|
|
||||||
closeMenu->Close();
|
|
||||||
closeMenu = (CMiniMenu*)closeMenu->GetParent();
|
|
||||||
} while (closeMenu->GetType() == eCtrlType_Menu);
|
|
||||||
|
|
||||||
m_pDPadMenu->ClearFlag(eCtrl_Highlight);
|
|
||||||
m_pDPadMenu = NULL;
|
|
||||||
UiCursorBus::Broadcast(&UiCursorInterface::IncrementVisibleCounter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniGUI::UpdateDPadMenu(const AzFramework::InputChannel& inputChannel)
|
|
||||||
{
|
|
||||||
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
|
|
||||||
const bool isPressed = inputChannel.IsStateBegan();
|
|
||||||
|
|
||||||
if (m_pDPadMenu)
|
|
||||||
{
|
|
||||||
if (channelId == AzFramework::InputDeviceGamepad::Button::B)
|
|
||||||
{
|
|
||||||
CloseDPadMenu();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isPressed)
|
|
||||||
{
|
|
||||||
if (channelId == AzFramework::InputDeviceGamepad::Button::DD ||
|
|
||||||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LD)
|
|
||||||
{
|
|
||||||
m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadDown);
|
|
||||||
}
|
|
||||||
else if (channelId == AzFramework::InputDeviceGamepad::Button::DU ||
|
|
||||||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LU)
|
|
||||||
{
|
|
||||||
m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadUp);
|
|
||||||
}
|
|
||||||
else if (channelId == AzFramework::InputDeviceGamepad::Button::DL ||
|
|
||||||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LL)
|
|
||||||
{
|
|
||||||
CMiniMenu* pNewMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadLeft);
|
|
||||||
|
|
||||||
//get previous root menu
|
|
||||||
if (pNewMenu == NULL)
|
|
||||||
{
|
|
||||||
int i = 0, nRootMenus = m_rootMenus.size();
|
|
||||||
|
|
||||||
for (i = 0; i < nRootMenus; i++)
|
|
||||||
{
|
|
||||||
if (m_rootMenus[i] == m_pDPadMenu)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
m_pDPadMenu->Close();
|
|
||||||
m_pDPadMenu->ClearFlag(eCtrl_Highlight);
|
|
||||||
|
|
||||||
m_pDPadMenu = (CMiniMenu*)m_rootMenus[i - 1];
|
|
||||||
m_pDPadMenu->Open();
|
|
||||||
m_pDPadMenu->SetFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
//else selected menu remains the same
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_pDPadMenu = pNewMenu;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (channelId == AzFramework::InputDeviceGamepad::Button::DR ||
|
|
||||||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LR)
|
|
||||||
{
|
|
||||||
CMiniMenu* pNewMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadRight);
|
|
||||||
|
|
||||||
//get next root menu
|
|
||||||
if (pNewMenu == NULL)
|
|
||||||
{
|
|
||||||
int i = 0, nRootMenus = m_rootMenus.size();
|
|
||||||
|
|
||||||
for (i = 0; i < nRootMenus; i++)
|
|
||||||
{
|
|
||||||
if (m_rootMenus[i] == m_pDPadMenu)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < nRootMenus - 1)
|
|
||||||
{
|
|
||||||
m_pDPadMenu->Close();
|
|
||||||
m_pDPadMenu->ClearFlag(eCtrl_Highlight);
|
|
||||||
|
|
||||||
m_pDPadMenu = (CMiniMenu*)m_rootMenus[i + 1];
|
|
||||||
m_pDPadMenu->Open();
|
|
||||||
m_pDPadMenu->SetFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
//else selected menu remains the same
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_pDPadMenu = pNewMenu;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (channelId == AzFramework::InputDeviceGamepad::Button::A)
|
|
||||||
{
|
|
||||||
m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_LButtonDown);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CMiniGUI::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel)
|
|
||||||
{
|
|
||||||
const AzFramework::InputDeviceId& deviceId = inputChannel.GetInputDevice().GetInputDeviceId();
|
|
||||||
if (AzFramework::InputDeviceMouse::IsMouseDevice(deviceId))
|
|
||||||
{
|
|
||||||
OnMouseInputEvent(inputChannel);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_inFocus)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!AzFramework::InputDeviceGamepad::IsGamepadDevice(deviceId))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_pDPadMenu)
|
|
||||||
{
|
|
||||||
UpdateDPadMenu(inputChannel);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float posX = 0.0f;
|
|
||||||
float posY = 0.0f;
|
|
||||||
const AzFramework::InputChannel::PositionData2D* positionData2D = inputChannel.GetCustomData<AzFramework::InputChannel::PositionData2D>();
|
|
||||||
if (positionData2D)
|
|
||||||
{
|
|
||||||
posX = positionData2D->m_normalizedPosition.GetX() * gEnv->pRenderer->GetWidth();
|
|
||||||
posY = positionData2D->m_normalizedPosition.GetY() * gEnv->pRenderer->GetHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
IMiniCtrl* pCtrl = GetCtrlFromPoint(posX, posY);
|
|
||||||
|
|
||||||
if (pCtrl)
|
|
||||||
{
|
|
||||||
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
|
|
||||||
if (channelId == AzFramework::InputDeviceGamepad::Button::A)
|
|
||||||
{
|
|
||||||
switch (inputChannel.GetState())
|
|
||||||
{
|
|
||||||
case AzFramework::InputChannel::State::Began:
|
|
||||||
pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonDown);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AzFramework::InputChannel::State::Ended:
|
|
||||||
pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonUp);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AzFramework::InputChannel::State::Updated:
|
|
||||||
pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonPressed);
|
|
||||||
|
|
||||||
//if we've clicked on a menu, enter menu selection mode, disable mouse
|
|
||||||
if (pCtrl->GetType() == eCtrlType_Menu)
|
|
||||||
{
|
|
||||||
SetDPadMenu(pCtrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::SetEventListener(IMiniGUIEventListener* pListener)
|
|
||||||
{
|
|
||||||
m_pEventListener = pListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniGUI::RemoveAllCtrl()
|
|
||||||
{
|
|
||||||
m_highlightedCtrl = NULL;
|
|
||||||
|
|
||||||
//reset all console variables to default state
|
|
||||||
Reset();
|
|
||||||
|
|
||||||
m_pRootCtrl->RemoveAllSubCtrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
//CMiniCtrl
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::Reset()
|
|
||||||
{
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::SaveState()
|
|
||||||
{
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->SaveState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::RestoreState()
|
|
||||||
{
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->RestoreState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::AddSubCtrl(IMiniCtrl* pCtrl)
|
|
||||||
{
|
|
||||||
assert(pCtrl);
|
|
||||||
_smart_ptr<IMiniCtrl> pTempCtrl(pCtrl);
|
|
||||||
IMiniCtrl* pParent = pCtrl->GetParent();
|
|
||||||
if (pParent)
|
|
||||||
{
|
|
||||||
pParent->RemoveSubCtrl(pCtrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
static_cast<CMiniCtrl*>(pCtrl)->m_pParent = this;
|
|
||||||
m_subCtrls.push_back(pCtrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::RemoveSubCtrl(IMiniCtrl* pCtrl)
|
|
||||||
{
|
|
||||||
assert(pCtrl);
|
|
||||||
_smart_ptr<IMiniCtrl> pTempCtrl(pCtrl);
|
|
||||||
IMiniCtrl* pParent = pCtrl->GetParent();
|
|
||||||
if (pParent == this)
|
|
||||||
{
|
|
||||||
static_cast<CMiniCtrl*>(pCtrl)->m_pParent = 0;
|
|
||||||
for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++)
|
|
||||||
{
|
|
||||||
if (m_subCtrls[i] == pCtrl)
|
|
||||||
{
|
|
||||||
m_subCtrls.erase(m_subCtrls.begin() + i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::RemoveAllSubCtrl()
|
|
||||||
{
|
|
||||||
int nSubCtrls = m_subCtrls.size();
|
|
||||||
|
|
||||||
if (nSubCtrls)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < nSubCtrls; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = m_subCtrls[i].get();
|
|
||||||
pSubCtrl->RemoveAllSubCtrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_subCtrls.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
IMiniCtrl* CMiniCtrl::GetCtrlFromPoint(float x, float y)
|
|
||||||
{
|
|
||||||
if (is_flag(eCtrl_Hidden))
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++)
|
|
||||||
{
|
|
||||||
float lx = x - m_rect.left;
|
|
||||||
float ly = y - m_rect.top;
|
|
||||||
IMiniCtrl* pHit = m_subCtrls[i]->GetCtrlFromPoint(lx, ly);
|
|
||||||
if (pHit)
|
|
||||||
{
|
|
||||||
return pHit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_rect.IsPointInside(x, y))
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::DrawCtrl(CDrawContext& dc)
|
|
||||||
{
|
|
||||||
OnPaint(dc);
|
|
||||||
|
|
||||||
dc.PushClientRect(m_rect);
|
|
||||||
|
|
||||||
for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++)
|
|
||||||
{
|
|
||||||
CMiniCtrl* pCtrl = static_cast<CMiniCtrl*>((IMiniCtrl*)m_subCtrls[i]);
|
|
||||||
if (!pCtrl->is_flag(eCtrl_Hidden))
|
|
||||||
{
|
|
||||||
pCtrl->DrawCtrl(dc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.PopClientRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
int CMiniCtrl::GetSubCtrlCount() const
|
|
||||||
{
|
|
||||||
return (int)m_subCtrls.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
IMiniCtrl* CMiniCtrl::GetSubCtrl(int nIndex) const
|
|
||||||
{
|
|
||||||
assert(nIndex >= 0 && nIndex < (int)m_subCtrls.size());
|
|
||||||
return m_subCtrls[nIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::SetRect(const Rect& rc)
|
|
||||||
{
|
|
||||||
m_rect = rc;
|
|
||||||
|
|
||||||
if (m_pCloseButton)
|
|
||||||
{
|
|
||||||
float width = rc.Width();
|
|
||||||
|
|
||||||
//relative position of cross box
|
|
||||||
Rect closeRect(width - 20.f, 0.f, width, 20.f);
|
|
||||||
m_pCloseButton->SetRect(closeRect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::SetVisible(bool state)
|
|
||||||
{
|
|
||||||
if (state)
|
|
||||||
{
|
|
||||||
clear_flag(eCtrl_Hidden);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
set_flag(eCtrl_Hidden);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_pCloseButton)
|
|
||||||
{
|
|
||||||
m_pCloseButton->SetVisible(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::AutoResize()
|
|
||||||
{
|
|
||||||
uint32 stringLen = m_title.length();
|
|
||||||
|
|
||||||
if (stringLen)
|
|
||||||
{
|
|
||||||
//just an approximation for now - should take into account font size / kerning
|
|
||||||
m_rect.right = m_rect.left + (8.5f * stringLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_requiresResize = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::StartMoving(float x, float y)
|
|
||||||
{
|
|
||||||
if (!m_moving)
|
|
||||||
{
|
|
||||||
m_prevX = x;
|
|
||||||
m_prevY = y;
|
|
||||||
m_moving = true;
|
|
||||||
|
|
||||||
m_pGUI->SetMovingCtrl(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::StopMoving()
|
|
||||||
{
|
|
||||||
if (m_moving)
|
|
||||||
{
|
|
||||||
m_moving = false;
|
|
||||||
m_pGUI->SetMovingCtrl(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::Move(float x, float y)
|
|
||||||
{
|
|
||||||
if (m_moving)
|
|
||||||
{
|
|
||||||
float moveX = x - m_prevX;
|
|
||||||
float moveY = y - m_prevY;
|
|
||||||
|
|
||||||
m_rect.top += moveY;
|
|
||||||
m_rect.bottom += moveY;
|
|
||||||
|
|
||||||
m_rect.left += moveX;
|
|
||||||
m_rect.right += moveX;
|
|
||||||
|
|
||||||
m_prevX = x;
|
|
||||||
m_prevY = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::OnEvent(float x, float y, EMiniCtrlEvent event)
|
|
||||||
{
|
|
||||||
switch (event)
|
|
||||||
{
|
|
||||||
case eCtrlEvent_LButtonDown:
|
|
||||||
{
|
|
||||||
if (is_flag(eCtrl_Highlight | eCtrl_Moveable))
|
|
||||||
{
|
|
||||||
StartMoving(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eCtrlEvent_LButtonUp:
|
|
||||||
if (m_moving)
|
|
||||||
{
|
|
||||||
StopMoving();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eCtrlEvent_MouseOver:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniCtrl::CreateCloseButton()
|
|
||||||
{
|
|
||||||
if (m_pGUI)
|
|
||||||
{
|
|
||||||
m_pCloseButton = m_pGUI->CreateCtrl(this, 100, eCtrlType_Button, 0, Rect(0, 0, 100, 20), "X");
|
|
||||||
|
|
||||||
if (m_pCloseButton)
|
|
||||||
{
|
|
||||||
m_pCloseButton->SetConnectedCtrl(this);
|
|
||||||
|
|
||||||
float width = m_rect.Width();
|
|
||||||
|
|
||||||
//relative position of cross box
|
|
||||||
Rect closeRect(width - 20.f, 0.f, width, 20.f);
|
|
||||||
m_pCloseButton->SetRect(closeRect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
@ -1,219 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Interface to the Mini GUI subsystem
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "ICryMiniGUI.h"
|
|
||||||
#include <Cry_Color.h>
|
|
||||||
|
|
||||||
#include <AzFramework/Input/Events/InputChannelEventListener.h>
|
|
||||||
|
|
||||||
#include <CryExtension/Impl/ClassWeaver.h>
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
class CMiniMenu;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Root window all other controls derive from
|
|
||||||
class CMiniCtrl
|
|
||||||
: public IMiniCtrl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CMiniCtrl()
|
|
||||||
: m_nFlags(0)
|
|
||||||
, m_id(0)
|
|
||||||
, m_renderCallback(NULL)
|
|
||||||
, m_fTextSize(12.f)
|
|
||||||
, m_prevX(0.f)
|
|
||||||
, m_prevY(0.f)
|
|
||||||
, m_moving(false)
|
|
||||||
, m_requiresResize(false)
|
|
||||||
, m_pCloseButton(NULL)
|
|
||||||
, m_saveStateOn(false)
|
|
||||||
{};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// IMiniCtrl interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void SaveState();
|
|
||||||
virtual void RestoreState();
|
|
||||||
|
|
||||||
virtual void SetGUI(IMiniGUI* pGUI) { m_pGUI = pGUI; };
|
|
||||||
virtual IMiniGUI* GetGUI() const { return m_pGUI; };
|
|
||||||
|
|
||||||
virtual int GetId() const { return m_id; };
|
|
||||||
virtual void SetId(int id) { m_id = id; };
|
|
||||||
|
|
||||||
virtual const char* GetTitle() const { return m_title; };
|
|
||||||
virtual void SetTitle(const char* title) { m_title = title; };
|
|
||||||
|
|
||||||
virtual Rect GetRect() const { return m_rect; }
|
|
||||||
virtual void SetRect(const Rect& rc);
|
|
||||||
|
|
||||||
virtual void SetFlag(uint32 flag) { set_flag(flag); }
|
|
||||||
virtual void ClearFlag(uint32 flag) { clear_flag(flag); };
|
|
||||||
virtual bool CheckFlag(uint32 flag) const { return is_flag(flag); }
|
|
||||||
|
|
||||||
virtual void AddSubCtrl(IMiniCtrl* pCtrl);
|
|
||||||
virtual void RemoveSubCtrl(IMiniCtrl* pCtrl);
|
|
||||||
virtual void RemoveAllSubCtrl();
|
|
||||||
virtual int GetSubCtrlCount() const;
|
|
||||||
virtual IMiniCtrl* GetSubCtrl(int nIndex) const;
|
|
||||||
virtual IMiniCtrl* GetParent() const { return m_pParent; };
|
|
||||||
|
|
||||||
virtual IMiniCtrl* GetCtrlFromPoint(float x, float y);
|
|
||||||
|
|
||||||
virtual void SetVisible(bool state);
|
|
||||||
|
|
||||||
virtual void OnEvent(float x, float y, EMiniCtrlEvent);
|
|
||||||
|
|
||||||
virtual bool SetRenderCallback(RenderCallback callback) { m_renderCallback = callback; return true; };
|
|
||||||
|
|
||||||
|
|
||||||
// Not implemented in base control
|
|
||||||
virtual bool SetControlCVar([[maybe_unused]] const char* sCVarName, [[maybe_unused]] float fOffValue, [[maybe_unused]] float fOnValue) { assert(0); return false; };
|
|
||||||
virtual bool SetClickCallback([[maybe_unused]] ClickCallback callback, [[maybe_unused]] void* pCallbackData) { assert(0); return false; };
|
|
||||||
virtual bool SetConnectedCtrl([[maybe_unused]] IMiniCtrl* pConnectedCtrl) { assert(0); return false; };
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual void AutoResize();
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual void CreateCloseButton();
|
|
||||||
|
|
||||||
void DrawCtrl(CDrawContext& dc);
|
|
||||||
|
|
||||||
virtual void Move(float x, float y);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void set_flag(uint32 flag) { m_nFlags |= flag; }
|
|
||||||
void clear_flag(uint32 flag) { m_nFlags &= ~flag; };
|
|
||||||
bool is_flag(uint32 flag) const { return (m_nFlags & flag) == flag; }
|
|
||||||
|
|
||||||
//dynamic movement
|
|
||||||
void StartMoving(float x, float y);
|
|
||||||
void StopMoving();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int m_id;
|
|
||||||
IMiniGUI* m_pGUI;
|
|
||||||
uint32 m_nFlags;
|
|
||||||
CryFixedStringT<32> m_title;
|
|
||||||
Rect m_rect;
|
|
||||||
_smart_ptr<IMiniCtrl> m_pParent;
|
|
||||||
std::vector<IMiniCtrlPtr> m_subCtrls;
|
|
||||||
RenderCallback m_renderCallback;
|
|
||||||
float m_fTextSize;
|
|
||||||
|
|
||||||
//optional close 'X' button on controls, ref counted by m_subCtrls
|
|
||||||
IMiniCtrl* m_pCloseButton;
|
|
||||||
|
|
||||||
//dynamic movement
|
|
||||||
float m_prevX;
|
|
||||||
float m_prevY;
|
|
||||||
bool m_moving;
|
|
||||||
bool m_requiresResize;
|
|
||||||
bool m_saveStateOn;
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
class CMiniGUI
|
|
||||||
: public IMiniGUI
|
|
||||||
, public AzFramework::InputChannelEventListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CRYINTERFACE_BEGIN()
|
|
||||||
CRYINTERFACE_ADD(IMiniGUI)
|
|
||||||
CRYINTERFACE_END()
|
|
||||||
CRYGENERATE_SINGLETONCLASS(CMiniGUI, "MiniGUI", 0x1a049b879a4e4b58, 0xac14026e17e6255e)
|
|
||||||
|
|
||||||
public:
|
|
||||||
void InitMetrics();
|
|
||||||
void ProcessInput();
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// IMiniGUI interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual void Init();
|
|
||||||
virtual void Done();
|
|
||||||
virtual void Draw();
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void SaveState();
|
|
||||||
virtual void RestoreState();
|
|
||||||
virtual void SetEnabled(bool status);
|
|
||||||
virtual void SetInFocus(bool status);
|
|
||||||
virtual bool InFocus() {return m_inFocus; }
|
|
||||||
|
|
||||||
virtual void SetEventListener(IMiniGUIEventListener* pListener);
|
|
||||||
|
|
||||||
virtual SMetrics& Metrics();
|
|
||||||
|
|
||||||
virtual void OnCommand(SCommand& cmd);
|
|
||||||
|
|
||||||
virtual void RemoveAllCtrl();
|
|
||||||
virtual IMiniCtrl* CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title);
|
|
||||||
|
|
||||||
virtual IMiniCtrl* GetCtrlFromPoint(float x, float y) const;
|
|
||||||
|
|
||||||
void SetHighlight(IMiniCtrl* pCtrl, bool bEnable, float x, float y);
|
|
||||||
void SetFocus(IMiniCtrl* pCtrl, bool bEnable);
|
|
||||||
|
|
||||||
// AzFramework::InputChannelEventListener
|
|
||||||
bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
|
|
||||||
AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); }
|
|
||||||
|
|
||||||
virtual void SetMovingCtrl(IMiniCtrl* pCtrl)
|
|
||||||
{
|
|
||||||
m_pMovingCtrl = pCtrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void OnMouseInputEvent(const AzFramework::InputChannel& inputChannel);
|
|
||||||
|
|
||||||
//DPad menu navigation
|
|
||||||
void UpdateDPadMenu(const AzFramework::InputChannel& inputChannel);
|
|
||||||
void SetDPadMenu(IMiniCtrl* pMenu);
|
|
||||||
void CloseDPadMenu();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool m_enabled;
|
|
||||||
bool m_inFocus;
|
|
||||||
|
|
||||||
SMetrics m_metrics;
|
|
||||||
|
|
||||||
_smart_ptr<CMiniCtrl> m_pRootCtrl;
|
|
||||||
|
|
||||||
_smart_ptr<IMiniCtrl> m_highlightedCtrl;
|
|
||||||
_smart_ptr<IMiniCtrl> m_focusCtrl;
|
|
||||||
|
|
||||||
IMiniGUIEventListener* m_pEventListener;
|
|
||||||
|
|
||||||
CMiniMenu* m_pDPadMenu;
|
|
||||||
IMiniCtrl* m_pMovingCtrl;
|
|
||||||
std::vector<minigui::IMiniCtrl*> m_rootMenus;
|
|
||||||
};
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H
|
|
||||||
@ -1,174 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Button implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "MiniInfoBox.h"
|
|
||||||
#include "DrawContext.h"
|
|
||||||
#include <ISystem.h>
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
|
|
||||||
CMiniInfoBox::CMiniInfoBox()
|
|
||||||
: m_fTextIndent(4)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniInfoBox::SaveState()
|
|
||||||
{
|
|
||||||
if (CheckFlag(eCtrl_Hidden))
|
|
||||||
{
|
|
||||||
m_saveStateOn = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_saveStateOn = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniInfoBox::Reset()
|
|
||||||
{
|
|
||||||
SetFlag(eCtrl_Hidden);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniInfoBox::RestoreState()
|
|
||||||
{
|
|
||||||
if (m_saveStateOn)
|
|
||||||
{
|
|
||||||
ClearFlag(eCtrl_Hidden);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniInfoBox::OnPaint(CDrawContext& dc)
|
|
||||||
{
|
|
||||||
if (m_requiresResize)
|
|
||||||
{
|
|
||||||
AutoResize();
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorB borderCol = dc.Metrics().clrFrameBorder;
|
|
||||||
ColorB backgroundCol = dc.Metrics().clrBackground;
|
|
||||||
|
|
||||||
if (!m_pGUI->InFocus())
|
|
||||||
{
|
|
||||||
borderCol = dc.Metrics().clrFrameBorderOutOfFocus;
|
|
||||||
backgroundCol.a = dc.Metrics().outOfFocusAlpha;
|
|
||||||
}
|
|
||||||
else if (m_moving)
|
|
||||||
{
|
|
||||||
borderCol = dc.Metrics().clrFrameBorderHighlight;
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.DrawFrame(m_rect, borderCol, backgroundCol);
|
|
||||||
|
|
||||||
dc.SetColor(dc.Metrics().clrTitle);
|
|
||||||
dc.DrawString(m_rect.left + 4, m_rect.top, dc.Metrics().fTitleSize, eTextAlign_Left, GetTitle());
|
|
||||||
|
|
||||||
float fTextSize = m_fTextSize;
|
|
||||||
if (fTextSize == 0)
|
|
||||||
{
|
|
||||||
fTextSize = dc.Metrics().fTextSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
float x = m_fTextIndent + m_rect.left + 8;
|
|
||||||
float y = m_rect.top + fTextSize + fTextSize;
|
|
||||||
// Draw entries.
|
|
||||||
for (int i = 0, num = (int)m_entries.size(); i < num; i++)
|
|
||||||
{
|
|
||||||
SInfoEntry& info = m_entries[i];
|
|
||||||
dc.SetColor(info.color);
|
|
||||||
dc.DrawString(x, y, info.textSize, eTextAlign_Left, info.text);
|
|
||||||
y += info.textSize * 0.8f;
|
|
||||||
if (y + info.textSize > m_rect.bottom)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_renderCallback)
|
|
||||||
{
|
|
||||||
m_renderCallback(m_rect.left, m_rect.top);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniInfoBox::OnEvent(float x, float y, EMiniCtrlEvent event)
|
|
||||||
{
|
|
||||||
CMiniCtrl::OnEvent(x, y, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniInfoBox::AddEntry(const char* str, ColorB col, float textSize)
|
|
||||||
{
|
|
||||||
SInfoEntry info;
|
|
||||||
|
|
||||||
info.color = col;
|
|
||||||
info.textSize = textSize;
|
|
||||||
cry_strcpy(info.text, str);
|
|
||||||
|
|
||||||
m_entries.push_back(info);
|
|
||||||
|
|
||||||
if (CheckFlag(eCtrl_AutoResize))
|
|
||||||
{
|
|
||||||
//set dirty flag instead of resizing for every elem
|
|
||||||
m_requiresResize = true; //AutoResize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniInfoBox::ClearEntries()
|
|
||||||
{
|
|
||||||
m_entries.clear();
|
|
||||||
m_requiresResize = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniInfoBox::AutoResize()
|
|
||||||
{
|
|
||||||
float width = 0.f;
|
|
||||||
float height = 32.f;
|
|
||||||
|
|
||||||
//must be at least the size of title and cross box
|
|
||||||
width = m_fTextIndent + ((float)m_title.size() * 14.f) + 30.f;
|
|
||||||
|
|
||||||
for (int i = 0, num = (int)m_entries.size(); i < num; i++)
|
|
||||||
{
|
|
||||||
SInfoEntry& info = m_entries[i];
|
|
||||||
|
|
||||||
uint32 strLength = strlen(info.text);
|
|
||||||
|
|
||||||
float strSize = info.textSize * strLength;
|
|
||||||
|
|
||||||
width = max(strSize, width);
|
|
||||||
height += info.textSize * 0.8f;
|
|
||||||
}
|
|
||||||
|
|
||||||
//scale width, could do with kerning info
|
|
||||||
width *= 0.6f;
|
|
||||||
|
|
||||||
Rect newRect = m_rect;
|
|
||||||
newRect.right = newRect.left + width;
|
|
||||||
newRect.bottom = newRect.top + height;
|
|
||||||
|
|
||||||
SetRect(newRect);
|
|
||||||
|
|
||||||
m_requiresResize = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Button implementation in the MiniGUI
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "MiniGUI.h"
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Root window all other controls derive from
|
|
||||||
class CMiniInfoBox
|
|
||||||
: public CMiniCtrl
|
|
||||||
, public IMiniInfoBox
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMiniInfoBox();
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMiniCtrl interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual EMiniCtrlType GetType() const { return eCtrlType_InfoBox; }
|
|
||||||
virtual void OnPaint(CDrawContext& dc);
|
|
||||||
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void SaveState();
|
|
||||||
virtual void RestoreState();
|
|
||||||
virtual void AutoResize();
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
virtual void SetTextIndent(float x) { m_fTextIndent = x; }
|
|
||||||
virtual void SetTextSize(float sz) { m_fTextSize = sz; }
|
|
||||||
virtual void ClearEntries();
|
|
||||||
virtual void AddEntry(const char* str, ColorB col, float textSize);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// IMiniTable interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual bool IsHidden() { return CheckFlag(eCtrl_Hidden); }
|
|
||||||
virtual void Hide(bool stat) { SetVisible(!stat); }
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static const int MAX_TEXT_LENGTH = 64;
|
|
||||||
|
|
||||||
struct SInfoEntry
|
|
||||||
{
|
|
||||||
char text[MAX_TEXT_LENGTH];
|
|
||||||
ColorB color;
|
|
||||||
float textSize;
|
|
||||||
};
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
std::vector<SInfoEntry> m_entries;
|
|
||||||
float m_fTextIndent;
|
|
||||||
};
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H
|
|
||||||
@ -1,364 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Button implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "MiniMenu.h"
|
|
||||||
#include "DrawContext.h"
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
|
|
||||||
CMiniMenu::CMiniMenu()
|
|
||||||
{
|
|
||||||
m_bVisible = false;
|
|
||||||
m_bSubMenu = false;
|
|
||||||
m_menuWidth = 0.f;
|
|
||||||
m_selectionIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::OnPaint(CDrawContext& dc)
|
|
||||||
{
|
|
||||||
CMiniButton::OnPaint(dc);
|
|
||||||
|
|
||||||
if (m_bSubMenu)
|
|
||||||
{
|
|
||||||
// Draw checked mark.
|
|
||||||
float x1 = m_rect.right - 12;
|
|
||||||
float y1 = m_rect.top + 3;
|
|
||||||
|
|
||||||
float x2 = m_rect.right - 3;
|
|
||||||
float y2 = (m_rect.bottom + m_rect.top) / 2;
|
|
||||||
|
|
||||||
float x3 = m_rect.right - 12;
|
|
||||||
float y3 = m_rect.bottom - 3;
|
|
||||||
|
|
||||||
dc.SetColor(ColorB(0, 0, 0, 255));
|
|
||||||
|
|
||||||
dc.DrawLine(x1, y1, x2, y2, 2.f);
|
|
||||||
dc.DrawLine(x2, y2, x3, y3, 2.f);
|
|
||||||
|
|
||||||
x1 -= 1;
|
|
||||||
x2 -= 1;
|
|
||||||
x3 -= 1;
|
|
||||||
y1 -= 1;
|
|
||||||
y2 -= 1;
|
|
||||||
y3 -= 1;
|
|
||||||
|
|
||||||
dc.SetColor(ColorB(255, 255, 255, 255));
|
|
||||||
|
|
||||||
dc.DrawLine(x1, y1, x2, y2, 2.f);
|
|
||||||
dc.DrawLine(x2, y2, x3, y3, 2.f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//dc.DrawFrame( m_rect,dc.Metrics().clrFrameBorder,dc.Metrics().clrBackground );
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::SetRect(const Rect& rc)
|
|
||||||
{
|
|
||||||
Rect newrc = rc;
|
|
||||||
newrc.bottom = newrc.top + m_pGUI->Metrics().fTitleSize + 2;
|
|
||||||
CMiniCtrl::SetRect(newrc);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::OnEvent(float x, float y, EMiniCtrlEvent event)
|
|
||||||
{
|
|
||||||
switch (event)
|
|
||||||
{
|
|
||||||
case eCtrlEvent_LButtonDown:
|
|
||||||
{
|
|
||||||
if (m_bVisible)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eCtrlEvent_MouseOff:
|
|
||||||
{
|
|
||||||
bool closeMenu = true;
|
|
||||||
IMiniCtrl* pCtrl = m_pGUI->GetCtrlFromPoint(x, y);
|
|
||||||
|
|
||||||
//check if the cursor is still in one of the menu's children
|
|
||||||
if (pCtrl)
|
|
||||||
{
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
if (pCtrl == GetSubCtrl(i))
|
|
||||||
{
|
|
||||||
closeMenu = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (closeMenu)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
|
|
||||||
if (m_pParent)
|
|
||||||
{
|
|
||||||
m_pParent->OnEvent(x, y, eCtrlEvent_MouseOff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CMiniMenu* CMiniMenu::UpdateSelection(EMiniCtrlEvent event)
|
|
||||||
{
|
|
||||||
CMiniMenu* pNewMenu = this;
|
|
||||||
IMiniCtrl* pCurrentSelection = NULL;
|
|
||||||
|
|
||||||
if (m_selectionIndex != -1)
|
|
||||||
{
|
|
||||||
pCurrentSelection = m_subCtrls[m_selectionIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event)
|
|
||||||
{
|
|
||||||
case eCtrlEvent_DPadLeft: //move to parent
|
|
||||||
if (!pCurrentSelection)
|
|
||||||
{
|
|
||||||
//move to previous root menu
|
|
||||||
pNewMenu = NULL;
|
|
||||||
}
|
|
||||||
else if (m_bSubMenu)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
pNewMenu = (CMiniMenu*)m_pParent.get();
|
|
||||||
//pNewMenu->SetFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eCtrlEvent_DPadRight: //move to child
|
|
||||||
if (!pCurrentSelection)
|
|
||||||
{
|
|
||||||
//move to next root menu
|
|
||||||
pNewMenu = NULL;
|
|
||||||
}
|
|
||||||
else if (pCurrentSelection->GetType() == eCtrlType_Menu)
|
|
||||||
{
|
|
||||||
pNewMenu = (CMiniMenu*)pCurrentSelection;
|
|
||||||
pNewMenu->Open();
|
|
||||||
pNewMenu->ClearFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eCtrlEvent_DPadUp: //move up list
|
|
||||||
if (m_bSubMenu)
|
|
||||||
{
|
|
||||||
if (m_selectionIndex > 0)
|
|
||||||
{
|
|
||||||
m_selectionIndex--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (m_selectionIndex >= 0)
|
|
||||||
{
|
|
||||||
m_selectionIndex--;
|
|
||||||
|
|
||||||
if (m_selectionIndex == -1)
|
|
||||||
{
|
|
||||||
SetFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eCtrlEvent_DPadDown: //move down the list
|
|
||||||
if (m_selectionIndex < (int)(m_subCtrls.size() - 1))
|
|
||||||
{
|
|
||||||
if (m_selectionIndex == -1)
|
|
||||||
{
|
|
||||||
ClearFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
m_selectionIndex++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eCtrlEvent_LButtonDown: //pass on button press
|
|
||||||
{
|
|
||||||
if (pCurrentSelection)
|
|
||||||
{
|
|
||||||
if (pCurrentSelection->GetType() == eCtrlType_Menu)
|
|
||||||
{
|
|
||||||
pNewMenu = (CMiniMenu*)pCurrentSelection;
|
|
||||||
}
|
|
||||||
pCurrentSelection->OnEvent(0, 0, eCtrlEvent_LButtonDown);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OnEvent(0, 0, eCtrlEvent_LButtonDown);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCurrentSelection)
|
|
||||||
{
|
|
||||||
pCurrentSelection->ClearFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_selectionIndex >= 0)
|
|
||||||
{
|
|
||||||
m_subCtrls[m_selectionIndex]->SetFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pNewMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::Open()
|
|
||||||
{
|
|
||||||
m_bVisible = true;
|
|
||||||
|
|
||||||
Rect rc(0, 0, m_menuWidth, 1);
|
|
||||||
|
|
||||||
//render sub menu to the right
|
|
||||||
if (m_bSubMenu)
|
|
||||||
{
|
|
||||||
CMiniMenu* pParent = static_cast<CMiniMenu*>(m_pParent.get());
|
|
||||||
rc.left = pParent->m_menuWidth; //rcParent.right;
|
|
||||||
rc.right = rc.left + m_menuWidth;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Rect rcThis = GetRect();
|
|
||||||
rc.top = rcThis.Height();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->ClearFlag(eCtrl_Hidden);
|
|
||||||
float h = pSubCtrl->GetRect().Height();
|
|
||||||
Rect rcCtrl = rc;
|
|
||||||
rcCtrl.top = rc.top;
|
|
||||||
rcCtrl.bottom = rcCtrl.top + h;
|
|
||||||
pSubCtrl->SetRect(rcCtrl);
|
|
||||||
rc.top += h;
|
|
||||||
}
|
|
||||||
|
|
||||||
//highlight first item when opened
|
|
||||||
if (m_bSubMenu)
|
|
||||||
{
|
|
||||||
m_selectionIndex = 0;
|
|
||||||
m_subCtrls[m_selectionIndex]->SetFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::Close()
|
|
||||||
{
|
|
||||||
m_bVisible = false;
|
|
||||||
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->SetFlag(eCtrl_Hidden);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_selectionIndex != -1)
|
|
||||||
{
|
|
||||||
m_subCtrls[m_selectionIndex]->ClearFlag(eCtrl_Highlight);
|
|
||||||
}
|
|
||||||
m_selectionIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::Reset()
|
|
||||||
{
|
|
||||||
m_bVisible = false;
|
|
||||||
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::SaveState()
|
|
||||||
{
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->SaveState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::RestoreState()
|
|
||||||
{
|
|
||||||
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
|
|
||||||
{
|
|
||||||
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
|
|
||||||
pSubCtrl->RestoreState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
void CMiniMenu::AddSubCtrl(IMiniCtrl* pCtrl)
|
|
||||||
{
|
|
||||||
assert(pCtrl);
|
|
||||||
pCtrl->SetFlag(eCtrl_Hidden);
|
|
||||||
pCtrl->SetFlag(eCtrl_NoBorder);
|
|
||||||
|
|
||||||
bool bSubMenu = false;
|
|
||||||
|
|
||||||
if (pCtrl->GetType() == eCtrlType_Menu)
|
|
||||||
{
|
|
||||||
CMiniMenu* pSubMenu = static_cast<CMiniMenu*>(pCtrl);
|
|
||||||
pSubMenu->m_bSubMenu = true;
|
|
||||||
bSubMenu = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_bSubMenu)
|
|
||||||
{
|
|
||||||
//menu is at least the size of title bar
|
|
||||||
m_menuWidth = max(m_menuWidth, strlen(GetTitle()) * 8.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* title = pCtrl->GetTitle();
|
|
||||||
|
|
||||||
if (title)
|
|
||||||
{
|
|
||||||
uint32 titleLen = strlen(title);
|
|
||||||
|
|
||||||
float width = (float)titleLen * 8.5f;
|
|
||||||
|
|
||||||
if (bSubMenu)
|
|
||||||
{
|
|
||||||
//increase width for submenu arrow
|
|
||||||
width += 10.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_menuWidth = max(m_menuWidth, width);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call parent
|
|
||||||
CMiniButton::AddSubCtrl(pCtrl);
|
|
||||||
}
|
|
||||||
MINIGUI_END
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Button implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "MiniGUI.h"
|
|
||||||
#include "MiniButton.h"
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Root window all other controls derive from
|
|
||||||
class CMiniMenu
|
|
||||||
: public CMiniButton
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMiniMenu();
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMiniCtrl interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual EMiniCtrlType GetType() const { return eCtrlType_Menu; }
|
|
||||||
virtual void SetRect(const Rect& rc);
|
|
||||||
virtual void OnPaint(CDrawContext& dc);
|
|
||||||
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
|
|
||||||
virtual void AddSubCtrl(IMiniCtrl* pCtrl);
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void SaveState();
|
|
||||||
virtual void RestoreState();
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//digital selection funcs
|
|
||||||
CMiniMenu* UpdateSelection(EMiniCtrlEvent event);
|
|
||||||
|
|
||||||
void Open();
|
|
||||||
void Close();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool m_bVisible;
|
|
||||||
bool m_bSubMenu;
|
|
||||||
float m_menuWidth;
|
|
||||||
|
|
||||||
int m_selectionIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H
|
|
||||||
@ -1,336 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Table implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "MiniTable.h"
|
|
||||||
#include "DrawContext.h"
|
|
||||||
|
|
||||||
#include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
CMiniTable::CMiniTable()
|
|
||||||
{
|
|
||||||
m_fTextSize = 15.f;
|
|
||||||
m_pageNum = 0;
|
|
||||||
m_pageSize = 35;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::OnPaint(CDrawContext& dc)
|
|
||||||
{
|
|
||||||
if (m_requiresResize)
|
|
||||||
{
|
|
||||||
AutoResize();
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorB borderCol;
|
|
||||||
ColorB backgroundCol = dc.Metrics().clrBackground;
|
|
||||||
|
|
||||||
if (m_pGUI->InFocus())
|
|
||||||
{
|
|
||||||
if (m_moving)
|
|
||||||
{
|
|
||||||
borderCol = dc.Metrics().clrFrameBorderHighlight;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
borderCol = dc.Metrics().clrFrameBorder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
borderCol = dc.Metrics().clrFrameBorderOutOfFocus;
|
|
||||||
backgroundCol.a = dc.Metrics().outOfFocusAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.DrawFrame(m_rect, borderCol, backgroundCol);
|
|
||||||
|
|
||||||
float fTextSize = m_fTextSize;
|
|
||||||
if (fTextSize == 0)
|
|
||||||
{
|
|
||||||
fTextSize = dc.Metrics().fTextSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
float indent = 4.f;
|
|
||||||
|
|
||||||
float x = m_rect.left + indent;
|
|
||||||
float y = m_rect.top + indent;
|
|
||||||
|
|
||||||
const int nColumns = m_columns.size();
|
|
||||||
int numEntries = nColumns > 0 ? m_columns[0].cells.size() : 0;
|
|
||||||
|
|
||||||
int startIdx = 0;
|
|
||||||
int endIdx = numEntries;
|
|
||||||
|
|
||||||
//Page number
|
|
||||||
if (nColumns)
|
|
||||||
{
|
|
||||||
int numPages = numEntries / m_pageSize;
|
|
||||||
|
|
||||||
if (numPages)
|
|
||||||
{
|
|
||||||
startIdx = m_pageNum * m_pageSize;
|
|
||||||
endIdx = min(startIdx + m_pageSize, numEntries);
|
|
||||||
dc.SetColor(ColorB(255, 255, 255, 255));
|
|
||||||
|
|
||||||
//print page details (adjust for zero indexed)
|
|
||||||
dc.DrawString(x, y, fTextSize, eTextAlign_Left, "Page %d of %d (Page Up / Page Down)", m_pageNum + 1, numPages + 1);
|
|
||||||
y += fTextSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float topOfTable = y;
|
|
||||||
|
|
||||||
for (int i = 0; i < nColumns; i++)
|
|
||||||
{
|
|
||||||
SColumn& column = m_columns[i];
|
|
||||||
|
|
||||||
y = topOfTable;
|
|
||||||
|
|
||||||
dc.SetColor(ColorB(32, 32, 255, 255));
|
|
||||||
|
|
||||||
dc.DrawString(x, y, fTextSize, eTextAlign_Left, column.name);
|
|
||||||
y += fTextSize + indent;
|
|
||||||
|
|
||||||
ColorB currentCol(255, 255, 255, 255);
|
|
||||||
|
|
||||||
dc.SetColor(currentCol);
|
|
||||||
|
|
||||||
const int nCells = column.cells.size();
|
|
||||||
|
|
||||||
for (int j = startIdx; j < endIdx && j < nCells; j++)
|
|
||||||
{
|
|
||||||
if (column.cells[j].col != currentCol)
|
|
||||||
{
|
|
||||||
dc.SetColor(column.cells[j].col);
|
|
||||||
currentCol = column.cells[j].col;
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.DrawString(x, y, fTextSize, eTextAlign_Left, column.cells[j].text);
|
|
||||||
y += fTextSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
x += column.width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::OnEvent(float x, float y, EMiniCtrlEvent event)
|
|
||||||
{
|
|
||||||
//movement
|
|
||||||
CMiniCtrl::OnEvent(x, y, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::AutoResize()
|
|
||||||
{
|
|
||||||
//must be at least the size of cross box
|
|
||||||
float tableWidth = 30.f;
|
|
||||||
|
|
||||||
float tableHeight = 0.f;
|
|
||||||
const float widthScale = 0.6f;
|
|
||||||
const int nColumns = m_columns.size();
|
|
||||||
|
|
||||||
int startIdx = 0;
|
|
||||||
int endIdx = 0;
|
|
||||||
|
|
||||||
bool bPageHeader = false;
|
|
||||||
|
|
||||||
//Update Page index
|
|
||||||
if (nColumns)
|
|
||||||
{
|
|
||||||
int numEntries = m_columns[0].cells.size();
|
|
||||||
|
|
||||||
//page index is now invalid, cap at max
|
|
||||||
if ((m_pageNum * m_pageSize) > numEntries)
|
|
||||||
{
|
|
||||||
m_pageNum = (numEntries / m_pageSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
startIdx = m_pageNum * m_pageSize;
|
|
||||||
endIdx = min(startIdx + m_pageSize, numEntries);
|
|
||||||
|
|
||||||
if (numEntries > m_pageSize)
|
|
||||||
{
|
|
||||||
bPageHeader = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < nColumns; i++)
|
|
||||||
{
|
|
||||||
SColumn& column = m_columns[i];
|
|
||||||
|
|
||||||
float width = strlen(column.name) * m_fTextSize;
|
|
||||||
|
|
||||||
int nCells = column.cells.size();
|
|
||||||
|
|
||||||
for (int j = startIdx; j < endIdx && j < nCells; j++)
|
|
||||||
{
|
|
||||||
width = max(width, strlen(column.cells[j].text) * m_fTextSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
width *= widthScale;
|
|
||||||
|
|
||||||
column.width = width;
|
|
||||||
tableWidth += width;
|
|
||||||
tableHeight = max(tableHeight, min(endIdx - startIdx, m_pageSize) * m_fTextSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
tableHeight += m_fTextSize * 2.f;
|
|
||||||
|
|
||||||
//Page index
|
|
||||||
if (bPageHeader)
|
|
||||||
{
|
|
||||||
tableHeight += m_fTextSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect newRect = m_rect;
|
|
||||||
|
|
||||||
newRect.right = newRect.left + tableWidth;
|
|
||||||
newRect.bottom = newRect.top + tableHeight;
|
|
||||||
|
|
||||||
SetRect(newRect);
|
|
||||||
|
|
||||||
m_requiresResize = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::Reset()
|
|
||||||
{
|
|
||||||
SetFlag(eCtrl_Hidden);
|
|
||||||
|
|
||||||
m_pageNum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::SaveState()
|
|
||||||
{
|
|
||||||
if (CheckFlag(eCtrl_Hidden))
|
|
||||||
{
|
|
||||||
m_saveStateOn = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_saveStateOn = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::RestoreState()
|
|
||||||
{
|
|
||||||
if (m_saveStateOn)
|
|
||||||
{
|
|
||||||
ClearFlag(eCtrl_Hidden);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int CMiniTable::AddColumn(const char* name)
|
|
||||||
{
|
|
||||||
assert(name);
|
|
||||||
|
|
||||||
SColumn col;
|
|
||||||
|
|
||||||
cry_strcpy(col.name, name);
|
|
||||||
col.width = strlen(col.name) * 8.f;
|
|
||||||
|
|
||||||
m_columns.push_back(col);
|
|
||||||
|
|
||||||
m_requiresResize = true;
|
|
||||||
|
|
||||||
return m_columns.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::RemoveColumns()
|
|
||||||
{
|
|
||||||
m_columns.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
int CMiniTable::AddData(int columnIndex, ColorB col, const char* format, ...)
|
|
||||||
{
|
|
||||||
assert(columnIndex < (int)m_columns.size());
|
|
||||||
|
|
||||||
SCell cell;
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
int written = vsnprintf_s(cell.text, MAX_TEXT_LENGTH, MAX_TEXT_LENGTH - 1, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
if (written == -1)
|
|
||||||
{
|
|
||||||
cell.text[MAX_TEXT_LENGTH - 1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
cell.col = col;
|
|
||||||
|
|
||||||
m_columns[columnIndex].cells.push_back(cell);
|
|
||||||
|
|
||||||
m_requiresResize = true;
|
|
||||||
|
|
||||||
return m_columns[columnIndex].cells.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::ClearTable()
|
|
||||||
{
|
|
||||||
const int nColumns = m_columns.size();
|
|
||||||
|
|
||||||
for (int i = 0; i < nColumns; i++)
|
|
||||||
{
|
|
||||||
m_columns[i].cells.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::SetVisible(bool state)
|
|
||||||
{
|
|
||||||
if (state)
|
|
||||||
{
|
|
||||||
clear_flag(eCtrl_Hidden);
|
|
||||||
AzFramework::InputChannelEventListener::Connect();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
set_flag(eCtrl_Hidden);
|
|
||||||
AzFramework::InputChannelEventListener::Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_pCloseButton)
|
|
||||||
{
|
|
||||||
m_pCloseButton->SetVisible(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMiniTable::Hide(bool stat)
|
|
||||||
{
|
|
||||||
SetVisible(!stat);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CMiniTable::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel)
|
|
||||||
{
|
|
||||||
if (!IsHidden() && inputChannel.IsStateBegan())
|
|
||||||
{
|
|
||||||
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
|
|
||||||
if (channelId == AzFramework::InputDeviceKeyboard::Key::NavigationPageUp)
|
|
||||||
{
|
|
||||||
m_pageNum++;
|
|
||||||
m_requiresResize = true;
|
|
||||||
}
|
|
||||||
else if (channelId == AzFramework::InputDeviceKeyboard::Key::NavigationPageDown)
|
|
||||||
{
|
|
||||||
if (m_pageNum > 0)
|
|
||||||
{
|
|
||||||
m_pageNum--;
|
|
||||||
m_requiresResize = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
MINIGUI_END
|
|
||||||
@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Table implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include "MiniGUI.h"
|
|
||||||
|
|
||||||
MINIGUI_BEGIN
|
|
||||||
|
|
||||||
class CMiniTable
|
|
||||||
: public CMiniCtrl
|
|
||||||
, public IMiniTable
|
|
||||||
, public AzFramework::InputChannelEventListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMiniTable();
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMiniCtrl interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual EMiniCtrlType GetType() const { return eCtrlType_Table; }
|
|
||||||
virtual void OnPaint(CDrawContext& dc);
|
|
||||||
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void SaveState();
|
|
||||||
virtual void RestoreState();
|
|
||||||
virtual void AutoResize();
|
|
||||||
virtual void SetVisible(bool state);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// IMiniTable interface implementation.
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//Add a new column to the table, return column index
|
|
||||||
virtual int AddColumn(const char* name);
|
|
||||||
|
|
||||||
//Remove all columns an associated data
|
|
||||||
virtual void RemoveColumns();
|
|
||||||
|
|
||||||
//Add data to specified column (add onto the end), return row index
|
|
||||||
virtual int AddData(int columnIndex, ColorB col, const char* format, ...);
|
|
||||||
|
|
||||||
//Clear all data from table
|
|
||||||
virtual void ClearTable();
|
|
||||||
|
|
||||||
virtual bool IsHidden() { return CheckFlag(eCtrl_Hidden); }
|
|
||||||
|
|
||||||
virtual void Hide(bool stat);
|
|
||||||
|
|
||||||
// AzFramework::InputChannelEventListener
|
|
||||||
bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
|
|
||||||
AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); }
|
|
||||||
|
|
||||||
static const int MAX_TEXT_LENGTH = 64;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
struct SCell
|
|
||||||
{
|
|
||||||
char text[MAX_TEXT_LENGTH];
|
|
||||||
ColorB col;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SColumn
|
|
||||||
{
|
|
||||||
char name[MAX_TEXT_LENGTH];
|
|
||||||
float width;
|
|
||||||
std::vector<SCell> cells;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<SColumn> m_columns;
|
|
||||||
int m_pageSize;
|
|
||||||
int m_pageNum;
|
|
||||||
};
|
|
||||||
|
|
||||||
MINIGUI_END
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H
|
|
||||||
@ -1,290 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Manages overload values (eg CPU,GPU etc)
|
|
||||||
// 1.0="everything is ok" 0.0="very bad frame rate"
|
|
||||||
// various systems can use this information and control what is currently in the scene
|
|
||||||
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
#include "OverloadSceneManager.h"
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Name: COverloadSceneManager
|
|
||||||
// Desc: Constructor
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
COverloadSceneManager::COverloadSceneManager()
|
|
||||||
{
|
|
||||||
InitialiseCVars();
|
|
||||||
|
|
||||||
m_currentFrameStat = 0;
|
|
||||||
|
|
||||||
ResetDefaultValues();
|
|
||||||
}//-------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Desc: static console callback functions
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
static void OnChange_osm_enabled(ICVar* pCVar)
|
|
||||||
{
|
|
||||||
if (pCVar->GetIVal() == 0)
|
|
||||||
{
|
|
||||||
gEnv->pOverloadSceneManager->Reset();
|
|
||||||
//gEnv->pRenderer->EnablePipelineProfiler(false); // would need push/pop since something else might have enabled it
|
|
||||||
}
|
|
||||||
else if (pCVar->GetIVal() == 1)
|
|
||||||
{
|
|
||||||
gEnv->pRenderer->EnablePipelineProfiler(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cmd_setFBScale(IConsoleCmdArgs* pParams)
|
|
||||||
{
|
|
||||||
int argCount = pParams->GetArgCount();
|
|
||||||
|
|
||||||
Vec2 newScale = Vec2(0.0f, 0.0f);
|
|
||||||
gEnv->pRenderer->EF_Query(EFQ_GetViewportDownscaleFactor, newScale);
|
|
||||||
|
|
||||||
if (argCount > 1)
|
|
||||||
{
|
|
||||||
newScale.x = clamp_tpl((float)atof(pParams->GetArg(1)), 0.0f, 1.0f);
|
|
||||||
|
|
||||||
if (argCount > 2)
|
|
||||||
{
|
|
||||||
newScale.y = clamp_tpl((float)atof(pParams->GetArg(2)), 0.0f, 1.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newScale.y = newScale.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
newScale = gEnv->pRenderer->SetViewportDownscale(newScale.x, newScale.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
int nWidth = gEnv->pRenderer->GetWidth();
|
|
||||||
int nHeight = gEnv->pRenderer->GetHeight();
|
|
||||||
|
|
||||||
gEnv->pLog->LogWithType(ILog::eInputResponse, "Current Viewport Resolution: %dx%d",
|
|
||||||
int(nWidth * newScale.x), int(nHeight * newScale.y));
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Name: InitialiseCVars
|
|
||||||
// Desc: Initialises CVars
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void COverloadSceneManager::InitialiseCVars()
|
|
||||||
{
|
|
||||||
// depending on final requirements, these could be made into const cvars
|
|
||||||
REGISTER_CVAR_CB(osm_enabled, 0, VF_NULL, "Enables/disables overload scene manager", &OnChange_osm_enabled);
|
|
||||||
REGISTER_CVAR(osm_historyLength, 5, VF_NULL, "Overload scene manager number of frames to record stats for");
|
|
||||||
REGISTER_CVAR(osm_targetFPS, 28.0f, VF_NULL, "Overload scene manager target frame rate");
|
|
||||||
REGISTER_CVAR(osm_targetFPSTolerance, 1.0f, VF_NULL, "The overload scene manager will make adjustments if fps is outside targetFPS +/- this value");
|
|
||||||
REGISTER_CVAR(osm_fbScaleDeltaDown, 5.0f, VF_NULL, "The speed multiplier for the overload scene manager frame buffer scaling down");
|
|
||||||
REGISTER_CVAR(osm_fbScaleDeltaUp, 1.0f, VF_NULL, "The speed multiplier for the overload scene manager frame buffer scaling up");
|
|
||||||
REGISTER_CVAR(osm_fbMinScale, 0.66f, VF_NULL, "The minimum scale factor the overload scene manager will drop to");
|
|
||||||
|
|
||||||
REGISTER_COMMAND("osm_setFBScale", cmd_setFBScale, VF_NULL, "Sets the framebuffer scale to either a single scale on both X and Y, or independent scales.\n"
|
|
||||||
"NOTE: Will be overridden immediately if Overload scene manager is still enabled - see osm_enabled");
|
|
||||||
}//-------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Name: Reset
|
|
||||||
// Desc: Resets overload scene manager outputs to sensible defaults
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void COverloadSceneManager::Reset()
|
|
||||||
{
|
|
||||||
ResetDefaultValues();
|
|
||||||
|
|
||||||
gEnv->pRenderer->SetViewportDownscale(m_fbScale, m_fbScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
void COverloadSceneManager::ResetDefaultValues()
|
|
||||||
{
|
|
||||||
m_fbScale = 1.0f;
|
|
||||||
m_scaleState = FBSCALE_AUTO;
|
|
||||||
m_lerpOverride.m_start = m_lerpOverride.m_length = 1.0f;
|
|
||||||
m_lerpOverride.m_reversed = false;
|
|
||||||
m_lerpAuto.m_start = m_lerpAuto.m_length = 1.0f;
|
|
||||||
m_lerpAuto.m_reversed = true;
|
|
||||||
m_fbAutoScale = m_fbOverrideDestScale = m_fbOverrideCurScale = 1.0f;
|
|
||||||
|
|
||||||
// completely reset history
|
|
||||||
for (int i = 0; i < osm_historyLength; i++)
|
|
||||||
{
|
|
||||||
SScenePerformanceStats& stats = m_sceneStats[i];
|
|
||||||
stats.frameRate = stats.gpuFrameRate = osm_targetFPS;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_smoothedSceneStats.frameRate = m_smoothedSceneStats.gpuFrameRate = osm_targetFPS;
|
|
||||||
}
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Name: Update
|
|
||||||
// Desc: Updates overload scene manager
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void COverloadSceneManager::Update()
|
|
||||||
{
|
|
||||||
if (!osm_enabled)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateStats();
|
|
||||||
ResizeFB();
|
|
||||||
}//-------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Name: OverrideScale and ResetScale
|
|
||||||
// Desc: sets up appropriate members for lerping between automatic framebuffer scale and manual
|
|
||||||
// overrides.
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void COverloadSceneManager::OverrideScale(float frameScale, float dt)
|
|
||||||
{
|
|
||||||
dt = max(dt, 1.0f / 1000.0f);
|
|
||||||
|
|
||||||
float curTime = gEnv->pTimer->GetCurrTime();
|
|
||||||
|
|
||||||
frameScale = clamp_tpl(frameScale, osm_fbMinScale, 1.0f);
|
|
||||||
|
|
||||||
m_fbOverrideDestScale = frameScale;
|
|
||||||
|
|
||||||
if (m_scaleState == FBSCALE_AUTO)
|
|
||||||
{
|
|
||||||
// remove any override lerp - we want to lerp straight from auto to the given value.
|
|
||||||
m_lerpOverride.m_start = m_lerpOverride.m_length = 1.0f;
|
|
||||||
m_lerpOverride.m_reversed = false;
|
|
||||||
m_fbOverrideCurScale = frameScale;
|
|
||||||
|
|
||||||
m_lerpAuto.m_start = curTime;
|
|
||||||
m_lerpAuto.m_length = dt;
|
|
||||||
m_lerpAuto.m_reversed = false;
|
|
||||||
}
|
|
||||||
else if (m_scaleState == FBSCALE_OVERRIDE)
|
|
||||||
{
|
|
||||||
m_lerpOverride.m_start = curTime;
|
|
||||||
m_lerpOverride.m_length = dt;
|
|
||||||
m_lerpOverride.m_reversed = false;
|
|
||||||
|
|
||||||
m_fbOverrideCurScale = m_fbScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_scaleState = FBSCALE_OVERRIDE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void COverloadSceneManager::ResetScale(float dt)
|
|
||||||
{
|
|
||||||
dt = max(dt, 1.0f / 1000.0f);
|
|
||||||
|
|
||||||
float curTime = gEnv->pTimer->GetCurrTime();
|
|
||||||
|
|
||||||
// remove any override lerp - we want to lerp straight to auto
|
|
||||||
m_lerpOverride.m_start = m_lerpOverride.m_length = 1.0f;
|
|
||||||
m_lerpOverride.m_reversed = false;
|
|
||||||
m_fbOverrideCurScale = m_fbOverrideDestScale = m_fbScale;
|
|
||||||
|
|
||||||
m_lerpAuto.m_start = curTime;
|
|
||||||
m_lerpAuto.m_length = dt;
|
|
||||||
m_lerpAuto.m_reversed = true; // want to lerp back to auto mode
|
|
||||||
|
|
||||||
m_scaleState = FBSCALE_AUTO;
|
|
||||||
}//-------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Name: UpdateStats
|
|
||||||
// Desc: Updates overload stats
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void COverloadSceneManager::UpdateStats()
|
|
||||||
{
|
|
||||||
m_currentFrameStat++;
|
|
||||||
|
|
||||||
if (m_currentFrameStat >= osm_historyLength)
|
|
||||||
{
|
|
||||||
m_currentFrameStat = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SScenePerformanceStats& currentStats = m_sceneStats[m_currentFrameStat];
|
|
||||||
const float frameLength = gEnv->pTimer->GetRealFrameTime() * 1000.0f;
|
|
||||||
const float gpuFrameLength = gEnv->pRenderer->GetGPUFrameTime() * 1000.0f;
|
|
||||||
|
|
||||||
currentStats.frameRate = frameLength > 0.0f ? 1000.0f / frameLength : 0.0f;
|
|
||||||
currentStats.gpuFrameRate = gpuFrameLength > 0.0f ? 1000.0f / gpuFrameLength : 0.0f;
|
|
||||||
|
|
||||||
CalculateSmoothedStats();
|
|
||||||
}//-------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void COverloadSceneManager::CalculateSmoothedStats()
|
|
||||||
{
|
|
||||||
m_smoothedSceneStats.Reset();
|
|
||||||
|
|
||||||
for (int i = 0; i < osm_historyLength; i++)
|
|
||||||
{
|
|
||||||
SScenePerformanceStats& stats = m_sceneStats[i];
|
|
||||||
m_smoothedSceneStats.frameRate += stats.frameRate;
|
|
||||||
m_smoothedSceneStats.gpuFrameRate += stats.gpuFrameRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_smoothedSceneStats.frameRate /= osm_historyLength;
|
|
||||||
m_smoothedSceneStats.gpuFrameRate /= osm_historyLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
float COverloadSceneManager::CalcFBScale()
|
|
||||||
{
|
|
||||||
float curTime = gEnv->pTimer->GetCurrTime();
|
|
||||||
|
|
||||||
// first calculate delta of the override lerp
|
|
||||||
float delta = clamp_tpl((curTime - m_lerpOverride.m_start) / m_lerpOverride.m_length, 0.0f, 1.0f);
|
|
||||||
if (m_lerpOverride.m_reversed)
|
|
||||||
{
|
|
||||||
delta = 1.0f - delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the current target override
|
|
||||||
float curOverrideScale = LERP(m_fbOverrideCurScale, m_fbOverrideDestScale, delta);
|
|
||||||
|
|
||||||
// calculate the delta from (or two) automatic scaling
|
|
||||||
delta = clamp_tpl((curTime - m_lerpAuto.m_start) / m_lerpAuto.m_length, 0.0f, 1.0f);
|
|
||||||
if (m_lerpAuto.m_reversed)
|
|
||||||
{
|
|
||||||
delta = 1.0f - delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
// final lerp from automatic to current override
|
|
||||||
return LERP(m_fbAutoScale, curOverrideScale, delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void COverloadSceneManager::ResizeFB()
|
|
||||||
{
|
|
||||||
// don't do anything for invalid framerates
|
|
||||||
if (m_smoothedSceneStats.gpuFrameRate < 5.0f || m_smoothedSceneStats.gpuFrameRate > 100.0f)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float fpsDiff = fabsf(m_smoothedSceneStats.gpuFrameRate - osm_targetFPS);
|
|
||||||
|
|
||||||
if (m_smoothedSceneStats.gpuFrameRate < osm_targetFPS - osm_targetFPSTolerance)
|
|
||||||
{
|
|
||||||
m_fbAutoScale -= osm_fbScaleDeltaDown / 1000.0f * fpsDiff;
|
|
||||||
}
|
|
||||||
else if (m_smoothedSceneStats.gpuFrameRate > osm_targetFPS + osm_targetFPSTolerance)
|
|
||||||
{
|
|
||||||
m_fbAutoScale += osm_fbScaleDeltaUp / 1000.0f * fpsDiff;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_fbAutoScale = clamp_tpl(m_fbAutoScale, osm_fbMinScale, 1.0f);
|
|
||||||
|
|
||||||
m_fbScale = clamp_tpl(CalcFBScale(), osm_fbMinScale, 1.0f);
|
|
||||||
|
|
||||||
gEnv->pRenderer->SetViewportDownscale(m_fbScale, m_fbScale);
|
|
||||||
}
|
|
||||||
@ -1,127 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_OVERLOADSCENEMANAGER_OVERLOADSCENEMANAGER_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_OVERLOADSCENEMANAGER_OVERLOADSCENEMANAGER_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
// Includes
|
|
||||||
#include "IOverloadSceneManager.h"
|
|
||||||
|
|
||||||
#define SCENE_PERFORMANCE_FRAME_HISTORY 64
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
// Name: SOverloadSceneStats
|
|
||||||
// Desc: Overload scene stats
|
|
||||||
// Author: James Chilvers
|
|
||||||
//==================================================================================================
|
|
||||||
struct SScenePerformanceStats
|
|
||||||
{
|
|
||||||
SScenePerformanceStats()
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reset()
|
|
||||||
{
|
|
||||||
frameRate = 0.0f;
|
|
||||||
gpuFrameRate = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float frameRate;
|
|
||||||
float gpuFrameRate;
|
|
||||||
};//------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//==================================================================================================
|
|
||||||
// Name: COverloadSceneManager
|
|
||||||
// Desc: Manages overload values (eg CPU,GPU etc)
|
|
||||||
// 1.0="everything is ok" 0.0="very bad frame rate"
|
|
||||||
// various systems can use this information and control what is currently in the scene
|
|
||||||
// Author: James Chilvers
|
|
||||||
//==================================================================================================
|
|
||||||
class COverloadSceneManager
|
|
||||||
: public IOverloadSceneManager
|
|
||||||
{
|
|
||||||
friend class COverloadDG;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
COverloadSceneManager();
|
|
||||||
~COverloadSceneManager() override = default;
|
|
||||||
|
|
||||||
virtual void Reset();
|
|
||||||
|
|
||||||
virtual void Update();
|
|
||||||
|
|
||||||
virtual void OverrideScale(float frameScale, float dt);
|
|
||||||
virtual void ResetScale(float dt);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void ResetDefaultValues();
|
|
||||||
void InitialiseCVars();
|
|
||||||
void UpdateStats();
|
|
||||||
void CalculateSmoothedStats();
|
|
||||||
void ResizeFB();
|
|
||||||
|
|
||||||
float CalcFBScale(); // performs all lerping and returns final framebuffer scale
|
|
||||||
|
|
||||||
// cvars
|
|
||||||
int osm_enabled;
|
|
||||||
int osm_historyLength;
|
|
||||||
float osm_targetFPS;
|
|
||||||
float osm_targetFPSTolerance;
|
|
||||||
float osm_fbScaleDeltaUp, osm_fbScaleDeltaDown;
|
|
||||||
float osm_fbMinScale;
|
|
||||||
|
|
||||||
SScenePerformanceStats m_smoothedSceneStats;
|
|
||||||
SScenePerformanceStats m_sceneStats[SCENE_PERFORMANCE_FRAME_HISTORY];
|
|
||||||
int m_currentFrameStat;
|
|
||||||
|
|
||||||
// current output scale, set to the renderer
|
|
||||||
float m_fbScale;
|
|
||||||
|
|
||||||
// Lerping behaviour is to lerp from autoscale to (lerp between cur/dest override)
|
|
||||||
//
|
|
||||||
// m_fbOverrideCurScale
|
|
||||||
// |
|
|
||||||
// |
|
|
||||||
// m_fbAutoScale ---- m_lerpAuto ---> m_lerpOverride
|
|
||||||
// |
|
|
||||||
// v
|
|
||||||
// m_fbOverrideDestScale
|
|
||||||
|
|
||||||
// framebuffer scales to support lerping & overriding of calculated scale
|
|
||||||
float m_fbAutoScale, m_fbOverrideCurScale, m_fbOverrideDestScale;
|
|
||||||
|
|
||||||
struct ScaleLerp
|
|
||||||
{
|
|
||||||
bool m_reversed; // Normally lerp is 0 -> 1. If reversed it's 1 -> 0
|
|
||||||
float m_start; // time in seconds
|
|
||||||
float m_length; // time in seconds
|
|
||||||
};
|
|
||||||
|
|
||||||
// lerpAuto is the lerp between auto scale and whatever override is.
|
|
||||||
// lerpOverride is the lerp between m_fbOverrideCurScale and m_fbOverrideDestScale
|
|
||||||
ScaleLerp m_lerpAuto, m_lerpOverride;
|
|
||||||
|
|
||||||
// State is the current destination of any lerps.
|
|
||||||
enum ScaleState
|
|
||||||
{
|
|
||||||
FBSCALE_AUTO,
|
|
||||||
FBSCALE_OVERRIDE,
|
|
||||||
} m_scaleState;
|
|
||||||
};//------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_OVERLOADSCENEMANAGER_OVERLOADSCENEMANAGER_H
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,478 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
||||||
|
|
||||||
// Description : Button implementation in the MiniGUI
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRYINCLUDE_CRYSYSTEM_PERFHUD_H
|
|
||||||
#define CRYINCLUDE_CRYSYSTEM_PERFHUD_H
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#include <IPerfHud.h>
|
|
||||||
|
|
||||||
#ifdef USE_PERFHUD
|
|
||||||
|
|
||||||
#include <AzFramework/Input/Events/InputChannelEventListener.h>
|
|
||||||
#include "MiniGUI/MiniInfoBox.h"
|
|
||||||
#include "MiniGUI/MiniTable.h"
|
|
||||||
|
|
||||||
//Macros for console based widget control
|
|
||||||
|
|
||||||
#define SET_WIDGET_DECL(WIDGET_NAME) \
|
|
||||||
static int s_cvar_##WIDGET_NAME; \
|
|
||||||
static void Set_##WIDGET_NAME##_Widget(ICVar * pCvar);
|
|
||||||
|
|
||||||
#define SET_WIDGET_DEF(WIDGET_NAME, WIDGET_ID) \
|
|
||||||
int CPerfHUD::s_cvar_##WIDGET_NAME = 0; \
|
|
||||||
void CPerfHUD::Set_##WIDGET_NAME##_Widget(ICVar * pCvar) \
|
|
||||||
{ \
|
|
||||||
ICryPerfHUD* pPerfHud = gEnv->pSystem->GetPerfHUD(); \
|
|
||||||
if (pPerfHud) \
|
|
||||||
{ \
|
|
||||||
int val = pCvar->GetIVal(); \
|
|
||||||
if (val) \
|
|
||||||
{ \
|
|
||||||
pPerfHud->SetState(eHudOutOfFocus); \
|
|
||||||
pPerfHud->EnableWidget(ICryPerfHUDWidget::WIDGET_ID, val); \
|
|
||||||
} \
|
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
pPerfHud->DisableWidget(ICryPerfHUDWidget::WIDGET_ID); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SET_WIDGET_COMMAND(COMMAND_NAME, WIDGET_NAME) \
|
|
||||||
REGISTER_CVAR2_CB(COMMAND_NAME, &s_cvar_##WIDGET_NAME, 0, VF_ALWAYSONCHANGE, "", Set_##WIDGET_NAME##_Widget);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Root window all other controls derive from
|
|
||||||
class CPerfHUD
|
|
||||||
: public ICryPerfHUD
|
|
||||||
, public minigui::IMiniGUIEventListener
|
|
||||||
, public AzFramework::InputChannelEventListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CRYINTERFACE_BEGIN()
|
|
||||||
CRYINTERFACE_ADD(ICryPerfHUD)
|
|
||||||
CRYINTERFACE_END()
|
|
||||||
CRYGENERATE_SINGLETONCLASS(CPerfHUD, "PerfHUD", 0x006945f9985e4ce2, 0x872120bfdec09ca5)
|
|
||||||
|
|
||||||
public:
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// ICryPerfHUD implementation
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual void Init();
|
|
||||||
virtual void Done();
|
|
||||||
virtual void Draw();
|
|
||||||
virtual void LoadBudgets();
|
|
||||||
virtual void SaveStats(const char* filename);
|
|
||||||
virtual void ResetWidgets();
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void Destroy();
|
|
||||||
|
|
||||||
//Set state through code (rather than using joypad input)
|
|
||||||
virtual void SetState(EHudState state);
|
|
||||||
|
|
||||||
virtual void Show(bool bRestoreState);
|
|
||||||
|
|
||||||
virtual void AddWidget(ICryPerfHUDWidget* pWidget);
|
|
||||||
virtual void RemoveWidget(ICryPerfHUDWidget* pWidget);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Gui Creation helper funcs
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual minigui::IMiniCtrl* CreateMenu(const char* name, minigui::IMiniCtrl* pParent = NULL);
|
|
||||||
virtual bool CreateCVarMenuItem(minigui::IMiniCtrl* pMenu, const char* name, const char* controlVar, float controlVarOn, float controlVarOff);
|
|
||||||
virtual bool CreateCallbackMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::ClickCallback callback, void* pCallbackData);
|
|
||||||
virtual minigui::IMiniInfoBox* CreateInfoMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::RenderCallback renderCallback, const minigui::Rect& rect, bool onAtStart = false);
|
|
||||||
virtual minigui::IMiniTable* CreateTableMenuItem(minigui::IMiniCtrl* pMenu, const char* name);
|
|
||||||
|
|
||||||
virtual minigui::IMiniCtrl* GetMenu(const char* name);
|
|
||||||
|
|
||||||
virtual void EnableWidget(ICryPerfHUDWidget::EWidgetID id, int mode);
|
|
||||||
virtual void DisableWidget(ICryPerfHUDWidget::EWidgetID id);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// WARNINGS - Widget Specific Interface
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual void AddWarning(float duration, const char* fmt, va_list argList);
|
|
||||||
virtual bool WarningsWindowEnabled() const;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// FPS - Widget Specific Interface
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual const std::vector<PerfBucket>* GetFpsBuckets(float& totalTime) const;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// IMiniGUIEventListener implementation
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual void OnCommand(minigui::SCommand& cmd);
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// AzFramework::InputChannelEventListener
|
|
||||||
bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
|
|
||||||
AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); }
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// CLICK CALLBACKS
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static void ResetCallback(void* data, bool status);
|
|
||||||
static void ReloadBudgetsCallback(void* data, bool status);
|
|
||||||
static void SaveStatsCallback(void* data, bool status);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// RENDER CALLBACKS
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static void DisplayRenderInfoCallback(const minigui::Rect& rect);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// CVAR CALLBACK
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static void CVarChangeCallback(ICVar* pCvar);
|
|
||||||
|
|
||||||
SET_WIDGET_DECL(Warnings);
|
|
||||||
SET_WIDGET_DECL(RenderSummary);
|
|
||||||
SET_WIDGET_DECL(RenderBatchStats);
|
|
||||||
SET_WIDGET_DECL(FpsBuckets);
|
|
||||||
SET_WIDGET_DECL(Particles);
|
|
||||||
SET_WIDGET_DECL(PakFile);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Static Data
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static const float OVERSCAN_X;
|
|
||||||
static const float OVERSCAN_Y;
|
|
||||||
|
|
||||||
static const ColorB COL_NORM;
|
|
||||||
static const ColorB COL_WARN;
|
|
||||||
static const ColorB COL_ERROR;
|
|
||||||
|
|
||||||
static const float TEXT_SIZE_NORM;
|
|
||||||
static const float TEXT_SIZE_WARN;
|
|
||||||
static const float TEXT_SIZE_ERROR;
|
|
||||||
|
|
||||||
static const float ACTIVATE_TIME_FROM_GAME;
|
|
||||||
static const float ACTIVATE_TIME_FROM_HUD;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void InitUI(minigui::IMiniGUI* pGUI);
|
|
||||||
void SetNextState();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
static int m_sys_perfhud;
|
|
||||||
static int m_sys_perfhud_pause;
|
|
||||||
|
|
||||||
int m_sys_perfhud_prev;
|
|
||||||
|
|
||||||
//record last menu position
|
|
||||||
float m_menuStartX;
|
|
||||||
float m_menuStartY;
|
|
||||||
|
|
||||||
bool m_hudCreated;
|
|
||||||
|
|
||||||
bool m_L1Pressed;
|
|
||||||
bool m_L2Pressed;
|
|
||||||
bool m_R1Pressed;
|
|
||||||
bool m_R2Pressed;
|
|
||||||
bool m_changingState;
|
|
||||||
bool m_hwMouseEnabled;
|
|
||||||
|
|
||||||
float m_triggersDownStartTime;
|
|
||||||
|
|
||||||
EHudState m_hudState;
|
|
||||||
EHudState m_hudLastState;
|
|
||||||
|
|
||||||
typedef std::vector< _smart_ptr<ICryPerfHUDWidget>, stl::STLGlobalAllocator<_smart_ptr<ICryPerfHUDWidget> > >::iterator TWidgetIterator;
|
|
||||||
|
|
||||||
std::vector< _smart_ptr<ICryPerfHUDWidget>, stl::STLGlobalAllocator<_smart_ptr<ICryPerfHUDWidget> > > m_widgets;
|
|
||||||
std::vector<minigui::IMiniCtrl*, stl::STLGlobalAllocator<minigui::IMiniCtrl*> > m_rootMenus;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CFpsWidget
|
|
||||||
: public ICryPerfHUDWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CFpsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud);
|
|
||||||
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void Update();
|
|
||||||
virtual bool ShouldUpdate();
|
|
||||||
virtual void LoadBudgets(XmlNodeRef perfXML);
|
|
||||||
virtual void SaveStats(XmlNodeRef statsXML);
|
|
||||||
virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); }
|
|
||||||
virtual void Disable() { m_pInfoBox->Hide(true); }
|
|
||||||
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
const std::vector<ICryPerfHUD::PerfBucket>* GetFpsBuckets(float& totalTime) const;
|
|
||||||
|
|
||||||
static void ResetCallback(void* data, bool status);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
static const uint32 NUM_FPS_BUCKETS_DEFAULT = 6;
|
|
||||||
|
|
||||||
struct PerfBucketsStat
|
|
||||||
{
|
|
||||||
std::vector<ICryPerfHUD::PerfBucket> buckets;
|
|
||||||
float totalTime;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <bool LESS_THAN>
|
|
||||||
void UpdateBuckets(PerfBucketsStat& buckets, float frameTime, const char* name, float stat);
|
|
||||||
|
|
||||||
// Data
|
|
||||||
static int m_cvarPerfHudFpsExclusive;
|
|
||||||
|
|
||||||
enum EPerfBucketType
|
|
||||||
{
|
|
||||||
BUCKET_FPS = 0,
|
|
||||||
BUCKET_GPU,
|
|
||||||
BUCKET_DP,
|
|
||||||
BUCKET_TYPE_NUM
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
PerfBucketsStat m_perfBuckets[BUCKET_TYPE_NUM];
|
|
||||||
|
|
||||||
float m_fpsBucketSize;
|
|
||||||
float m_fpsBudget;
|
|
||||||
float m_dpBudget;
|
|
||||||
float m_dpBucketSize;
|
|
||||||
|
|
||||||
minigui::IMiniInfoBox* m_pInfoBox;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CRenderStatsWidget
|
|
||||||
: public ICryPerfHUDWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CRenderStatsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud);
|
|
||||||
|
|
||||||
virtual void Reset() {}
|
|
||||||
virtual void Update();
|
|
||||||
virtual bool ShouldUpdate();
|
|
||||||
virtual void LoadBudgets(XmlNodeRef perfXML);
|
|
||||||
virtual void SaveStats(XmlNodeRef statsXML);
|
|
||||||
virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); }
|
|
||||||
virtual void Disable() { m_pInfoBox->Hide(true); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
//budgets
|
|
||||||
float m_fpsBudget;
|
|
||||||
uint32 m_dpBudget;
|
|
||||||
uint32 m_polyBudget;
|
|
||||||
uint32 m_postEffectBudget;
|
|
||||||
uint32 m_shadowCastBudget;
|
|
||||||
uint32 m_particlesBudget;
|
|
||||||
|
|
||||||
//runtime data
|
|
||||||
struct SRuntimeData
|
|
||||||
{
|
|
||||||
Vec3 cameraPos;
|
|
||||||
Ang3 cameraRot;
|
|
||||||
float fps;
|
|
||||||
uint32 nDrawPrims;
|
|
||||||
uint32 nPolys;
|
|
||||||
uint32 nPostEffects;
|
|
||||||
uint32 nFwdLights;
|
|
||||||
uint32 nFwdShadowLights;
|
|
||||||
uint32 nDefLights;
|
|
||||||
uint32 nDefShadowLights;
|
|
||||||
uint32 nDefCubeMaps;
|
|
||||||
int nParticles;
|
|
||||||
bool hdrEnabled;
|
|
||||||
bool renderThreadEnabled;
|
|
||||||
};
|
|
||||||
|
|
||||||
SRuntimeData m_runtimeData;
|
|
||||||
minigui::IMiniInfoBox* m_pInfoBox;
|
|
||||||
ICryPerfHUD* m_pPerfHUD;
|
|
||||||
uint32 m_buildNum;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CStreamingStatsWidget
|
|
||||||
: public ICryPerfHUDWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CStreamingStatsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud);
|
|
||||||
|
|
||||||
virtual void Reset() {}
|
|
||||||
virtual void Update();
|
|
||||||
virtual bool ShouldUpdate();
|
|
||||||
virtual void LoadBudgets(XmlNodeRef perfXML);
|
|
||||||
virtual void SaveStats(XmlNodeRef statsXML) {};
|
|
||||||
virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); }
|
|
||||||
virtual void Disable() { m_pInfoBox->Hide(true); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
//float m_maxMeshSizeArroundMB;
|
|
||||||
//float m_maxTextureSizeArroundMB;
|
|
||||||
minigui::IMiniInfoBox* m_pInfoBox;
|
|
||||||
ICryPerfHUD* m_pPerfHUD;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class CWarningsWidget
|
|
||||||
: public ICryPerfHUDWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CWarningsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud);
|
|
||||||
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void Update();
|
|
||||||
virtual bool ShouldUpdate();
|
|
||||||
virtual void LoadBudgets(XmlNodeRef perfXML) {};
|
|
||||||
virtual void SaveStats(XmlNodeRef statsXML);
|
|
||||||
virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); }
|
|
||||||
virtual void Disable() { m_pInfoBox->Hide(true); }
|
|
||||||
|
|
||||||
void AddWarningV(float duration, const char* fmt, va_list argList);
|
|
||||||
void AddWarning(float duration, const char* warning);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
static const uint32 WARNING_LENGTH = 64;
|
|
||||||
|
|
||||||
struct SWarning
|
|
||||||
{
|
|
||||||
char text[WARNING_LENGTH];
|
|
||||||
float remainingDuration;
|
|
||||||
};
|
|
||||||
|
|
||||||
minigui::IMiniInfoBox* m_pInfoBox;
|
|
||||||
|
|
||||||
typedef std::vector< SWarning > TSWarnings;
|
|
||||||
|
|
||||||
TSWarnings m_warnings;
|
|
||||||
|
|
||||||
CryMT::queue<SWarning> m_threadWarnings;
|
|
||||||
|
|
||||||
threadID m_nMainThreadId;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CRenderBatchWidget
|
|
||||||
: public ICryPerfHUDWidget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CRenderBatchWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud);
|
|
||||||
|
|
||||||
virtual void Reset();
|
|
||||||
virtual void Update();
|
|
||||||
virtual bool ShouldUpdate();
|
|
||||||
virtual void LoadBudgets(XmlNodeRef perfXML) {};
|
|
||||||
virtual void SaveStats(XmlNodeRef statsXML);
|
|
||||||
virtual void Enable(int mode);
|
|
||||||
virtual void Disable();
|
|
||||||
|
|
||||||
void Update_ModeGpuTimes();
|
|
||||||
void Update_ModeBatchStats();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
struct BatchInfoGpuTimes
|
|
||||||
{
|
|
||||||
const char* name;
|
|
||||||
uint32 nBatches;
|
|
||||||
float gpuTime;
|
|
||||||
int numVerts;
|
|
||||||
int numIndices;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BatchInfoSortGpuTimes
|
|
||||||
{
|
|
||||||
inline bool operator() (const BatchInfoGpuTimes& lhs, const BatchInfoGpuTimes& rhs) const
|
|
||||||
{
|
|
||||||
return lhs.gpuTime > rhs.gpuTime;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BatchInfoPerPass
|
|
||||||
{
|
|
||||||
const char* name;
|
|
||||||
uint16 nBatches;
|
|
||||||
uint16 nInstances;
|
|
||||||
uint16 nZpass;
|
|
||||||
uint16 nShadows;
|
|
||||||
uint16 nGeneral;
|
|
||||||
uint16 nTransparent;
|
|
||||||
uint16 nMisc;
|
|
||||||
ColorB col;
|
|
||||||
|
|
||||||
BatchInfoPerPass()
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reset()
|
|
||||||
{
|
|
||||||
name = NULL;
|
|
||||||
nBatches = 0;
|
|
||||||
nInstances = 0;
|
|
||||||
nZpass = 0;
|
|
||||||
nShadows = 0;
|
|
||||||
nGeneral = 0;
|
|
||||||
nTransparent = 0;
|
|
||||||
nMisc = 0;
|
|
||||||
col.set(255, 255, 255, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator += (const BatchInfoPerPass& rhs)
|
|
||||||
{
|
|
||||||
nBatches += rhs.nBatches;
|
|
||||||
nInstances += rhs.nInstances;
|
|
||||||
nZpass += rhs.nZpass;
|
|
||||||
nShadows += rhs.nShadows;
|
|
||||||
nGeneral += rhs.nGeneral;
|
|
||||||
nTransparent += rhs.nTransparent;
|
|
||||||
nMisc += rhs.nMisc;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BatchInfoSortPerPass
|
|
||||||
{
|
|
||||||
inline bool operator() (const BatchInfoPerPass* lhs, const BatchInfoPerPass* rhs) const
|
|
||||||
{
|
|
||||||
return lhs->nBatches > rhs->nBatches;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
enum EDisplayMode
|
|
||||||
{
|
|
||||||
DISPLAY_MODE_NONE = 0,
|
|
||||||
DISPLAY_MODE_BATCH_STATS,
|
|
||||||
DISPLAY_MODE_GPU_TIMES,
|
|
||||||
DISPLAY_MODE_NUM,
|
|
||||||
};
|
|
||||||
|
|
||||||
minigui::IMiniTable* m_pTable;
|
|
||||||
ICVar* m_pRStatsCVar;
|
|
||||||
EDisplayMode m_displayMode;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //USE_PERFHUD
|
|
||||||
|
|
||||||
#endif // CRYINCLUDE_CRYSYSTEM_PERFHUD_H
|
|
||||||
@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
* its licensors.
|
|
||||||
*
|
|
||||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
* distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "CrySystem_precompiled.h"
|
|
||||||
|
|
||||||
#include <AzCore/UnitTest/TestTypes.h>
|
|
||||||
#include <AzCore/UnitTest/UnitTest.h>
|
|
||||||
#include <AzTest/AzTest.h>
|
|
||||||
|
|
||||||
#include <AzCore/Memory/OSAllocator.h>
|
|
||||||
|
|
||||||
#include "CrySizerImpl.h"
|
|
||||||
|
|
||||||
namespace UnitTest
|
|
||||||
{
|
|
||||||
class CrySizerTest
|
|
||||||
: public AllocatorsFixture
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void SetUp() override
|
|
||||||
{
|
|
||||||
AZ::AllocatorInstance<AZ::LegacyAllocator>::Create();
|
|
||||||
AZ::AllocatorInstance<CryStringAllocator>::Create();
|
|
||||||
|
|
||||||
m_sizer = new CrySizerImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TearDown() override
|
|
||||||
{
|
|
||||||
delete m_sizer;
|
|
||||||
|
|
||||||
AZ::AllocatorInstance<CryStringAllocator>::Destroy();
|
|
||||||
AZ::AllocatorInstance<AZ::LegacyAllocator>::Destroy();
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
CrySizerImpl* m_sizer;
|
|
||||||
}; //class StatisticsTest
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The key data structures fed to ICrySizer in CTerrain::GetMemoryUsage(class ICrySizer* pSizer):
|
|
||||||
* 1. structs and classes.
|
|
||||||
* 2. PodArray< of structs / classes>
|
|
||||||
* 3. PodArray< of pointers>
|
|
||||||
*/
|
|
||||||
TEST_F(CrySizerTest, CrySizerTest_AddSomeObjectsUsedInCTerrain_GetExpectedSize)
|
|
||||||
{
|
|
||||||
struct TmpStruct
|
|
||||||
{
|
|
||||||
AZ::u32 a;
|
|
||||||
AZ::u32 b;
|
|
||||||
};
|
|
||||||
TmpStruct tmpStructObj;
|
|
||||||
//Tracking a simple struct.
|
|
||||||
m_sizer->AddObjectSize(&tmpStructObj);
|
|
||||||
|
|
||||||
//The AddObject method is only available when using the ICrySizer base class.
|
|
||||||
ICrySizer* sizer = static_cast<ICrySizer*>(m_sizer);
|
|
||||||
|
|
||||||
const int numItemsPerArray = 1024;
|
|
||||||
|
|
||||||
//PodArray of structs
|
|
||||||
PodArray<TmpStruct> podArrayOfTmpStruct;
|
|
||||||
podArrayOfTmpStruct.resize(numItemsPerArray);
|
|
||||||
sizer->AddObject(podArrayOfTmpStruct);
|
|
||||||
|
|
||||||
//PodArray of pointers
|
|
||||||
PodArray<TmpStruct*> podArrayOfTmpStructPointers;
|
|
||||||
podArrayOfTmpStructPointers.resize(numItemsPerArray);
|
|
||||||
sizer->AddObject(podArrayOfTmpStructPointers);
|
|
||||||
|
|
||||||
//PodArray of Array2d of pointers.
|
|
||||||
const int array2dAxisSize = 64;
|
|
||||||
PodArray<Array2d<TmpStruct*>> podArrayOfArray2d;
|
|
||||||
podArrayOfArray2d.resize(numItemsPerArray);
|
|
||||||
for (int i = 0; i < numItemsPerArray; ++i)
|
|
||||||
{
|
|
||||||
//Array2d will allocate array2dAxisSize * array2dAxisSize elements.
|
|
||||||
podArrayOfArray2d[i].Allocate(array2dAxisSize);
|
|
||||||
}
|
|
||||||
sizer->AddObject(podArrayOfArray2d);
|
|
||||||
|
|
||||||
//Calculate the total expected size
|
|
||||||
const size_t expectedSizeOfArray2d = sizeof(Array2d<TmpStruct*>)
|
|
||||||
+ (array2dAxisSize * array2dAxisSize) * sizeof(TmpStruct*);
|
|
||||||
const size_t expectedTotalSize = sizeof(TmpStruct)
|
|
||||||
+ numItemsPerArray * sizeof(TmpStruct)
|
|
||||||
+ numItemsPerArray * sizeof(TmpStruct*)
|
|
||||||
+ numItemsPerArray * expectedSizeOfArray2d;
|
|
||||||
|
|
||||||
EXPECT_EQ( m_sizer->GetTotalSize(), expectedTotalSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
}//namespace UnitTest
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue