Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: introduce patch data classes and crude parser upgrade beginnings #1

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions addons/func_godot/src/core/func_godot_map_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,13 @@ class FuncGodotTextureData:

func _init(in_name: String):
name = in_name

class FuncGodotPatchVertex:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't feel like a great solution, but for now and simplicity's sake, I'm treating patches as special objects, though in the map file proper they are part of brush defs.

var vertex: Vector3
var uv: Vector2

class FuncGodotPatch:
var subdivisons: int
var indices: Vector2
var vertices: Array[FuncGodotPatchVertex]
var texture_idx: int
72 changes: 71 additions & 1 deletion addons/func_godot/src/core/func_godot_map_parser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var scope:= FuncGodotMapParser.ParseScope.FILE
var comment: bool = false
var entity_idx: int = -1
var brush_idx: int = -1
var patch_idx: int = -1
var face_idx: int = -1
var component_idx: int = 0
var prop_key: String = ""
Expand All @@ -13,6 +14,8 @@ var valve_uvs: bool = false
var current_face: FuncGodotMapData.FuncGodotFace
var current_brush: FuncGodotMapData.FuncGodotBrush
var current_entity: FuncGodotMapData.FuncGodotEntity
var current_patch: FuncGodotMapData.FuncGodotPatch


var map_data: FuncGodotMapData
var _keep_tb_groups: bool = false
Expand All @@ -23,13 +26,15 @@ func _init(in_map_data: FuncGodotMapData) -> void:
func load(map_file: String, keep_tb_groups: bool) -> bool:
current_face = FuncGodotMapData.FuncGodotFace.new()
current_brush = FuncGodotMapData.FuncGodotBrush.new()
current_patch = FuncGodotMapData.FuncGodotPatch.new()
current_entity = FuncGodotMapData.FuncGodotEntity.new()

scope = FuncGodotMapParser.ParseScope.FILE
comment = false
entity_idx = -1
brush_idx = -1
face_idx = -1
patch_idx = -1
component_idx = 0
valve_uvs = false
_keep_tb_groups = keep_tb_groups
Expand Down Expand Up @@ -79,6 +84,8 @@ func set_scope(new_scope: FuncGodotMapParser.ParseScope) -> void:
print("Switching to property value scope")
ParseScope.BRUSH:
print("Switching to brush " + str(brush_idx) + " scope")
ParseScope.PATCHDEF2:
print("Switching to patchDef2 brush " + str(brush_idx) + "scope")
ParseScope.PLANE_0:
print("Switching to face " + str(face_idx) + " plane 0 scope")
ParseScope.PLANE_1:
Expand All @@ -104,7 +111,13 @@ func set_scope(new_scope: FuncGodotMapParser.ParseScope) -> void:
"""
scope = new_scope

var current_line: int = 00

func token(buf_str: String) -> void:
prints("Read line %s" % current_line, buf_str)

current_line += 1

if comment:
return
elif buf_str == "//":
Expand All @@ -117,6 +130,7 @@ func token(buf_str: String) -> void:
entity_idx += 1
brush_idx = -1
set_scope(FuncGodotMapParser.ParseScope.ENTITY)

FuncGodotMapParser.ParseScope.ENTITY:
if buf_str.begins_with('"'):
prop_key = buf_str.substr(1)
Expand All @@ -130,6 +144,7 @@ func token(buf_str: String) -> void:
elif buf_str == "}":
commit_entity()
set_scope(FuncGodotMapParser.ParseScope.FILE)

FuncGodotMapParser.ParseScope.PROPERTY_VALUE:
var is_first = buf_str[0] == '"'
var is_last = buf_str.right(1) == '"'
Expand All @@ -146,14 +161,62 @@ func token(buf_str: String) -> void:
if is_last:
current_entity.properties[prop_key] = current_property.substr(1, len(current_property) - 2)
set_scope(FuncGodotMapParser.ParseScope.ENTITY)

FuncGodotMapParser.ParseScope.BRUSH:
if buf_str == "(":

# VL: Perhaps unnecessary as typically NRC spits out "patchDef2". However, I can't
# say if that's entirely consistent across all .map editors and files.

if buf_str.to_lower() == "patchdef2":
patch_idx += 1
set_scope(FuncGodotMapParser.ParseScope.PATCHDEF2)

elif buf_str == "(":
face_idx += 1
component_idx = 0
set_scope(FuncGodotMapParser.ParseScope.PLANE_0)

elif buf_str == "}":
commit_brush()
set_scope(FuncGodotMapParser.ParseScope.ENTITY)

FuncGodotMapParser.ParseScope.PATCHDEF2:
#{
#patchDef2 # we are here at start
#{
# texture_name
#( 3 3 0 0 0 ) # subdiv X/Y, face attributes (surface, content flags, value ; unused for now)
#(
#( ( -128 -496 -32 -2 -2 ) ( -128 -368 -32 0 -2 ) ( -128 -240 -32 2 -2 ) )
#( ( 0 -496 -32 -2 0 ) ( 0 -368 32 0 0 ) ( 0 -240 -32 2 0 ) )
#( ( 128 -496 -32 -2 2 ) ( 128 -368 -32 0 2 ) ( 128 -240 -32 2 2 ) )
#)
#}
#}

if buf_str == "{":
component_idx = 0

elif buf_str == "(":
prints("Reading vertices")

elif buf_str == ")":
prints("closing vertex")

elif buf_str == "}":
commit_patch()
set_scope(FuncGodotMapParser.ParseScope.ENTITY)

else:
match component_idx:
0: current_patch.texture_idx = map_data.register_texture(buf_str)
1,2: current_patch.indices[component_idx - 1] = float(buf_str)
3,4,5: pass # Contains face attributes, which are currently unsupported in func_godot

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needs the rest of the vertices to be read


component_idx += 1


FuncGodotMapParser.ParseScope.PLANE_0:
if buf_str == ")":
component_idx = 0
Expand Down Expand Up @@ -286,13 +349,20 @@ func commit_face() -> void:
current_brush.faces.append(current_face)
current_face = FuncGodotMapData.FuncGodotFace.new()

func commit_patch() -> void:

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this overall split is kept, the current_patch = patch.new() call should happen here instead of where it's currently happening



return

# Nested
enum ParseScope{
FILE,
COMMENT,
ENTITY,
PROPERTY_VALUE,
BRUSH,
PATCHDEF2,
PLANE_0,
PLANE_1,
PLANE_2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ extends Resource
## Skip texture path that gets applied to caulk and nodrawnonsolid shaders.
@export var skip_texture: String = "textures/special/skip"

##@experimental
## Map format used when saving. [br][br]NetRadiant will also automatically
## filter out unsupported data according to the map type. Using [b]mapq3[/b] allows quadratic Bezier patches.
@export_enum("mapq1", "mapq3") var map_type: String = "mapq1"

## Generates completed text for a .shader file.
func build_shader_text() -> String:
var shader_text: String = ""
Expand Down Expand Up @@ -79,7 +84,7 @@ func build_gamepack_text() -> String:
if sound_type != sound_types[-1]:
soundtypes_str += " "

var gamepack_text: String = """<?xml version="1.0"?>
var gamepack_text: String = """<?xm000l version="1.0"?>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops- fix this

<game
type="q3"
index="1"
Expand All @@ -96,7 +101,7 @@ func build_gamepack_text() -> String:
texturetypes="%s"
modeltypes="%s"
soundtypes="%s"
maptypes="mapq1"
maptypes="%s"
shaders="quake3"
entityclass="halflife"
entityclasstype="fgd"
Expand Down Expand Up @@ -126,6 +131,7 @@ func build_gamepack_text() -> String:
texturetypes_str,
modeltypes_str,
soundtypes_str,
map_type,
default_scale,
clip_texture,
skip_texture,
Expand Down