Просмотр исходного кода

Merge branch 'master' of github.com:taylor001/crown

Daniele Bartolini 10 лет назад
Родитель
Сommit
ebe61dc6fe

+ 93 - 145
exporters/blender-2.68/__init__.py

@@ -1,163 +1,111 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
 #
-#  This program is free software; you can redistribute it and/or
-#  modify it under the terms of the GNU General Public License
-#  as published by the Free Software Foundation; either version 2
-#  of the License, or (at your option) any later version.
+# Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
+# License: https://github.com/taylor001/crown/blob/master/LICENSE
 #
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software Foundation,
-#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8-80 compliant>
 
 bl_info = {
-    "name": "Crown Engine .mesh format",
-    "author": "Crown Engine Team",
-    "blender": (2, 58, 0),
-    "location": "File > Import-Export",
-    "description": "Export Crown Engine .mesh models",
-    "warning": "",
-    "tracker_url": "",
-    "support": 'OFFICIAL',
-    "category": "Import-Export"}
+	"name": "Crown Engine .mesh format",
+	"author": "Daniele Bartolini",
+	"blender": (2, 58, 0),
+	"location": "File > Import-Export",
+	"description": "Export Crown Engine .mesh models",
+	"warning": "",
+	"tracker_url": "https://github.com/taylor001/crown",
+	"support": 'OFFICIAL',
+	"category": "Import-Export"}
 
 if "bpy" in locals():
-    import imp
-    if "export_crown" in locals():
-        imp.reload(export_crown)
-
+	import imp
+	if "export_crown" in locals():
+		imp.reload(export_crown)
 
 import bpy
 from bpy.props import (BoolProperty,
-                       FloatProperty,
-                       StringProperty,
-                       EnumProperty,
-                       )
+	FloatProperty,
+	StringProperty,
+	EnumProperty,
+	)
 from bpy_extras.io_utils import (ExportHelper,
-                                 path_reference_mode,
-                                 axis_conversion,
-                                 )
-
-class ExportCrownMesh(bpy.types.Operator, ExportHelper):
-    """Save a Crown Engine .mesh model"""
-
-    bl_idname = "model.mesh"
-    bl_label = 'Export .mesh'
-    bl_options = {'PRESET'}
-
-    filename_ext = ".mesh"
-    filter_glob = StringProperty(
-            default="*.mesh;",
-            options={'HIDDEN'},
-            )
-
-    # context group
-    use_selection = BoolProperty(
-            name="Selection Only",
-            description="Export selected objects only",
-            default=False,
-            )
-
-    # object group
-    use_mesh_modifiers = BoolProperty(
-            name="Apply Modifiers",
-            description="Apply modifiers (preview resolution)",
-            default=True,
-            )
-
-    # extra data group
-    use_normals = BoolProperty(
-            name="Include Normals",
-            description="",
-            default=True,
-            )
-    use_uvs = BoolProperty(
-            name="Include UVs",
-            description="Write out the active UV coordinates",
-            default=True,
-            )
-    use_triangles = BoolProperty(
-            name="Triangulate Faces",
-            description="Convert all faces to triangles",
-            default=True,
-            )
-
-    # grouping group
-    keep_vertex_order = BoolProperty(
-            name="Keep Vertex Order",
-            description="",
-            default=False,
-            )
-
-    axis_forward = EnumProperty(
-            name="Forward",
-            items=(('X', "X Forward", ""),
-                   ('Y', "Y Forward", ""),
-                   ('Z', "Z Forward", ""),
-                   ('-X', "-X Forward", ""),
-                   ('-Y', "-Y Forward", ""),
-                   ('-Z', "-Z Forward", ""),
-                   ),
-            default='-Z',
-            )
-    axis_up = EnumProperty(
-            name="Up",
-            items=(('X', "X Up", ""),
-                   ('Y', "Y Up", ""),
-                   ('Z', "Z Up", ""),
-                   ('-X', "-X Up", ""),
-                   ('-Y', "-Y Up", ""),
-                   ('-Z', "-Z Up", ""),
-                   ),
-            default='Y',
-            )
-    global_scale = FloatProperty(
-            name="Scale",
-            min=0.01, max=1000.0,
-            default=1.0,
-            )
-
-    check_extension = True
-
-    def execute(self, context):
-        from . import export_crown
-
-        from mathutils import Matrix
-        keywords = self.as_keywords(ignore=("axis_forward",
-                                            "axis_up",
-                                            "global_scale",
-                                            "check_existing",
-                                            "filter_glob",
-                                            ))
-
-        global_matrix = (Matrix.Scale(self.global_scale, 4) *
-                         axis_conversion(to_forward=self.axis_forward,
-                                         to_up=self.axis_up,
-                                         ).to_4x4())
-
-        keywords["global_matrix"] = global_matrix
-        return export_crown.save(self, context, **keywords)
+	path_reference_mode,
+	axis_conversion,
+	)
+
+class MyExporter(bpy.types.Operator, ExportHelper):
+	"""Save a Crown Engine .mesh model"""
+
+	bl_idname = "model.mesh"
+	bl_label = 'Export .mesh'
+	bl_options = {'PRESET'}
+
+	filename_ext = ".mesh"
+	filter_glob = StringProperty(
+		default="*.mesh;",
+		options={'HIDDEN'},
+		)
+
+	use_selection = BoolProperty(
+		name="Selection Only",
+		description="Export selected objects only",
+		default=False,
+		)
+
+	use_mesh_modifiers = BoolProperty(
+		name="Apply Modifiers",
+		description="Apply modifiers (preview resolution)",
+		default=True,
+		)
+
+	use_normals = BoolProperty(
+		name="Include Normals",
+		description="",
+		default=True,
+		)
+
+	use_uvs = BoolProperty(
+		name="Include UVs",
+		description="Write out the active UV coordinates",
+		default=True,
+		)
+
+	use_triangles = BoolProperty(
+		name="Triangulate Faces",
+		description="Convert all faces to triangles",
+		default=True,
+		)
+
+	global_scale = FloatProperty(
+		name="Scale",
+		min=0.01, max=1000.0,
+		default=1.0,
+		)
+
+	def execute(self, context):
+		from . import export_crown
+
+		from mathutils import Matrix
+		keywords = self.as_keywords(ignore=("axis_forward",
+					"axis_up",
+					"global_scale",
+					"check_existing",
+					"filter_glob",
+					))
+
+		scale_mt = Matrix.Scale(self.global_scale, 4)
+		global_matrix = (scale_mt * axis_conversion(to_forward='-Z', to_up='Y').to_4x4())
+
+		keywords["global_matrix"] = global_matrix
+		return export_crown.save(self, context, **keywords)
 
 def menu_func_export(self, context):
-    self.layout.operator(ExportCrownMesh.bl_idname, text="Crown Engine (.mesh)")
-
+	self.layout.operator(MyExporter.bl_idname, text="Crown Engine (.mesh)")
 
 def register():
-    bpy.utils.register_module(__name__)
-    bpy.types.INFO_MT_file_export.append(menu_func_export)
-
+	bpy.utils.register_module(__name__)
+	bpy.types.INFO_MT_file_export.append(menu_func_export)
 
 def unregister():
-    bpy.utils.unregister_module(__name__)
-    bpy.types.INFO_MT_file_export.remove(menu_func_export)
+	bpy.utils.unregister_module(__name__)
+	bpy.types.INFO_MT_file_export.remove(menu_func_export)
 
 if __name__ == "__main__":
-    register()
+	register()

+ 146 - 333
exporters/blender-2.68/export_crown.py

@@ -1,38 +1,14 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
 #
-#  This program is free software; you can redistribute it and/or
-#  modify it under the terms of the GNU General Public License
-#  as published by the Free Software Foundation; either version 2
-#  of the License, or (at your option) any later version.
+# Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
+# License: https://github.com/taylor001/crown/blob/master/LICENSE
 #
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software Foundation,
-#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8 compliant>
 
 import os
-import time
-
 import bpy
 import mathutils
 import bpy_extras.io_utils
 
-
-def name_compat(name):
-	if name is None:
-		return 'None'
-	else:
-		return name.replace(' ', '_')
-
-
+# Triangulates the mesh me
 def mesh_triangulate(me):
 	import bmesh
 	bm = bmesh.new()
@@ -41,20 +17,13 @@ def mesh_triangulate(me):
 	bm.to_mesh(me)
 	bm.free()
 
-def write_file(filepath, objects, scene,
-			   EXPORT_TRI=True,
-			   EXPORT_NORMALS=True,
-			   EXPORT_UV=True,
-			   EXPORT_APPLY_MODIFIERS=True,
-			   EXPORT_KEEP_VERT_ORDER=False,
-			   EXPORT_GLOBAL_MATRIX=None,
-			   ):
-	"""
-	Basic write function. The context and options must be already set
-	This can be accessed externaly
-	eg.
-	write( '/home/user/project/foobar.mesh', Blender.Object.GetSelected() ) # Using default options.
-	"""
+def write_file(file, objects, scene,
+	EXPORT_TRI=True,
+	EXPORT_NORMALS=True,
+	EXPORT_UV=True,
+	EXPORT_APPLY_MODIFIERS=True,
+	EXPORT_GLOBAL_MATRIX=None,
+	):
 
 	if EXPORT_GLOBAL_MATRIX is None:
 		EXPORT_GLOBAL_MATRIX = mathutils.Matrix()
@@ -65,254 +34,132 @@ def write_file(filepath, objects, scene,
 	def veckey2d(v):
 		return round(v[0], 6), round(v[1], 6)
 
-	print('Crown Engine .mesh export path: %r' % filepath)
-
-	time1 = time.time()
-
-	file = open(filepath, "wb")
 	def fw(string):
 		file.write(bytes(string, 'UTF-8'))
 
-	# Write Header
-	# FIXME FIXME FIXME
-
-	# Initialize totals, these are updated each object
-	totverts = totuvco = totno = 0
-
-	face_vert_index = 1
-
-	globalNormals = {}
+	def write_mesh(ob, name):
+		try:
+			me = ob.to_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW', calc_tessface=False)
+		except RuntimeError:
+			me = None
 
-	copy_set = set()
+		if me is None:
+			return
 
-	# Get all meshes
-	for ob_main in objects:
+		me.transform(EXPORT_GLOBAL_MATRIX * ob.matrix_world)
 
-		# ignore dupli children
-		if ob_main.parent and ob_main.parent.dupli_type in {'VERTS', 'FACES'}:
-			# XXX
-			print(ob_main.name, 'is a dupli child - ignoring')
-			continue
+		if EXPORT_TRI:
+			mesh_triangulate(me)
 
-		obs = []
-		if ob_main.dupli_type != 'NONE':
-			# XXX
-			print('creating dupli_list on', ob_main.name)
-			ob_main.dupli_list_create(scene)
-
-			obs = [(dob.object, dob.matrix) for dob in ob_main.dupli_list]
-
-			# XXX debug print
-			print(ob_main.name, 'has', len(obs), 'dupli children')
+		if EXPORT_UV:
+			faceuv = len(me.uv_textures) > 0
+			if faceuv:
+				uv_texture = me.uv_textures.active.data[:]
+				uv_layer = me.uv_layers.active.data[:]
 		else:
-			obs = [(ob_main, ob_main.matrix_world)]
-
-		for ob, ob_mat in obs:
+			faceuv = False
 
-			try:
-				me = ob.to_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW', calc_tessface=False)
-			except RuntimeError:
-				me = None
-
-			if me is None:
-				continue
-
-			me.transform(EXPORT_GLOBAL_MATRIX * ob_mat)
-
-			if EXPORT_TRI:
-				# _must_ do this first since it re-allocs arrays
-				mesh_triangulate(me)
-
-			if EXPORT_UV:
-				faceuv = len(me.uv_textures) > 0
-				if faceuv:
-					uv_texture = me.uv_textures.active.data[:]
-					uv_layer = me.uv_layers.active.data[:]
-			else:
-				faceuv = False
-
-			me_verts = me.vertices[:]
-
-			# Make our own list so it can be sorted to reduce context switching
-			face_index_pairs = [(face, index) for index, face in enumerate(me.polygons)]
-			# faces = [ f for f in me.tessfaces ]
-
-			# Edges not supported by Crown Engine .mesh
-			edges = []
-
-			if not (len(face_index_pairs) + len(edges) + len(me.vertices)):  # Make sure there is somthing to write
-
-				# clean up
-				bpy.data.meshes.remove(me)
-
-				continue  # dont bother with this mesh.
-
-			if EXPORT_NORMALS and face_index_pairs:
-				me.calc_normals()
-
-			materials = me.materials[:]
-			material_names = [m.name if m else None for m in materials]
-
-			# avoid bad index errors
-			if not materials:
-				materials = [None]
-				material_names = [name_compat(None)]
-
-			# Sort by Material, then images
-			# so we dont over context switch in the obj file.
-			if EXPORT_KEEP_VERT_ORDER:
-				pass
-			else:
-				if faceuv:
-					sort_func = lambda a: (a[0].material_index,
-											   hash(uv_texture[a[1]].image),
-											   a[0].use_smooth)
-				elif len(materials) > 1:
-					sort_func = lambda a: (a[0].material_index,
-											   a[0].use_smooth)
+		if not (len(me.polygons) + len(me.vertices)):
+			bpy.data.meshes.remove(me)
+			return
+
+		if EXPORT_NORMALS and me.polygons:
+			me.calc_normals()
+
+		normals = {}
+		texcoords = {}
+
+		def write_positions(me):
+			for v in me.vertices:
+				posKey = veckey3d(v.co)
+				fw(" %.6f %.6f %.6f" % posKey)
+
+		def write_normals(me):
+			for f in me.polygons:
+				if f.use_smooth:
+					for v_idx in f.vertices:
+						v = me.vertices[v_idx]
+						noKey = veckey3d(v.normal)
+						if noKey not in normals:
+							normals[noKey] = len(normals)
+							fw(" %.6f %.6f %.6f" % noKey)
 				else:
-					# no materials
-					sort_func = lambda a: a[0].use_smooth
-
-				face_index_pairs.sort(key=sort_func)
-
-				del sort_func
-
-			# Set the default mat to no material and no image.
-			contextMat = 0, 0  # Can never be this, so we will label a new material the first chance we get.
-			contextSmooth = None  # Will either be true or false,  set bad to force initialization switch.
-
-			fw("{\n")
-			# Positions
-			fw("    position = [\n")
-			for v in me_verts:
-				fw('        %.6f %.6f %.6f\n' % v.co[:])
-			fw("    ]\n")
-
-			# NORMAL, Smooth/Non smoothed.
-			if EXPORT_NORMALS:
-				fw("    normal = [\n")
-				for f, f_index in face_index_pairs:
-					if f.use_smooth:
-						for v_idx in f.vertices:
-							v = me_verts[v_idx]
-							noKey = veckey3d(v.normal)
-							if noKey not in globalNormals:
-								globalNormals[noKey] = totno
-								totno += 1
-								fw('        %.6f %.6f %.6f\n' % noKey)
-					else:
-						# Hard, 1 normal from the face.
-						noKey = veckey3d(f.normal)
-						if noKey not in globalNormals:
-							globalNormals[noKey] = totno
-							totno += 1
-							fw('        %.6f %.6f %.6f\n' % noKey)
-				fw("    ]\n")
-
-			# UV
-			if faceuv:
-				# in case removing some of these dont get defined.
-				uv = uvkey = uv_dict = f_index = uv_index = uv_ls = uv_k = None
-
-				uv_face_mapping = [None] * len(face_index_pairs)
-
-				uv_dict = {}  # could use a set() here
-
-				fw("    texcoord = [\n")
-				for f, f_index in face_index_pairs:
-					uv_ls = uv_face_mapping[f_index] = []
-					for uv_index, l_index in enumerate(f.loop_indices):
-						uv = uv_layer[l_index].uv
-
-						uvkey = veckey2d(uv)
-						try:
-							uv_k = uv_dict[uvkey]
-						except:
-							uv_k = uv_dict[uvkey] = len(uv_dict)
-							fw('        %.6f %.6f\n' % uv[:])
-						uv_ls.append(uv_k)
-				fw("    ]\n")
-
-				uv_unique_count = len(uv_dict)
-
-				del uv, uvkey, uv_dict, f_index, uv_index, uv_ls, uv_k
-				# Only need uv_unique_count and uv_face_mapping
-
-			# Index array
-			fw('    index = [\n')
-
-			# Position indices
-			fw('        [ ')
-			for f, f_index in face_index_pairs:
-				f_smooth = f.use_smooth
-				f_v = [(vi, me_verts[v_idx]) for vi, v_idx in enumerate(f.vertices)]
-
-				for vi, v in f_v:
-					fw('%d ' % (v.index + totverts))
-			fw(']\n')
-
-			# Normal indices
+					noKey = veckey3d(f.normal)
+					if noKey not in normals:
+						normals[noKey] = len(normals)
+						fw(" %.6f %.6f %.6f" % noKey)
+
+		def write_texcoords(me):
+			for f in me.polygons:
+				for loop_index in f.loop_indices:
+					uv = uv_layer[loop_index].uv
+					uvkey = veckey2d(uv)
+					if uvkey not in texcoords:
+						texcoords[uvkey] = len(texcoords)
+						fw(" %.6f %.6f" % uvkey)
+
+		def write_position_indices(me):
+			for f in me.polygons:
+				for v_idx in f.vertices:
+					v = me.vertices[v_idx]
+					fw(' %d' % v.index)
+
+		def write_normal_indices(me, normals):
+			for f in me.polygons:
+				if f.use_smooth:
+					for v_idx in f.vertices:
+						v = me.vertices[v_idx]
+						fw(' %d' % (normals[veckey3d(v.normal)]))
+				else:
+					no = normals[veckey3d(f.normal)]
+					for v_idx in f.vertices:
+						fw(' %d' % no)
+
+		def write_texcoord_indices(me, texcoords):
+			for f in me.polygons:
+				for loop_index in f.loop_indices:
+					uv = uv_layer[loop_index].uv
+					fw(' %d' % texcoords[veckey2d(uv)])
+
+		def write_indices(me, normals, texcoords):
+			fw("        indices = {\n");
+			fw("            size = %d\n" % (3*len(me.polygons))) # Assume triagles
+			fw("            data = [\n")
+			fw("                ["); write_position_indices(me); fw(" ]\n")
 			if EXPORT_NORMALS:
-				fw('        [ ')
-				for f, f_index in face_index_pairs:
-					f_smooth = f.use_smooth
-					f_v = [(vi, me_verts[v_idx]) for vi, v_idx in enumerate(f.vertices)]
-
-					if f_smooth: # Use smoothed normals
-						for vi, v in f_v:
-							fw('%d,' % (globalNormals[veckey3d(v.normal)]))
-					else: # No smoothing, face normals
-						no = globalNormals[veckey3d(f.normal)]
-						for vi, v in f_v:
-							fw('%d ' % no)
-				fw(']\n')
-
-			# Texcoords
-			if faceuv:
-				fw('        [ ')
-				for f, f_index in face_index_pairs:
-					f_smooth = f.use_smooth
-					f_v = [(vi, me_verts[v_idx]) for vi, v_idx in enumerate(f.vertices)]
-
-					for vi, v in f_v:
-						fw('%d ' % (totuvco + uv_face_mapping[f_index][vi]))
-				fw(']')
-			fw(']\n')
-
-			# Make the indices global rather then per mesh
-			totverts += len(me_verts)
+				fw("                ["); write_normal_indices(me, normals); fw(" ]\n")
 			if faceuv:
-				totuvco += uv_unique_count
-
-			# clean up
-			bpy.data.meshes.remove(me)
+				fw("                ["); write_texcoord_indices(me, texcoords); fw(" ]\n")
+			fw("            ]\n")
+			fw("        }\n")
 
-		if ob_main.dupli_type != 'NONE':
-			ob_main.dupli_list_clear()
+		fw("    \"%s\" = {\n" % name)
+		fw("        position = ["); write_positions(me); fw(" ]\n")
+		if EXPORT_NORMALS:
+			fw("        normal = ["); write_normals(me); fw(" ]\n")
+		if faceuv:
+			fw("        texcoord = ["); write_texcoords(me); fw(" ]\n")
+		write_indices(me, normals, texcoords);
+		fw("    }\n")
 
-	fw('}\n')
-	file.close()
+		bpy.data.meshes.remove(me)
 
-	# copy all collected files.
-	bpy_extras.io_utils.path_reference_copy(copy_set)
-
-	print("OBJ Export time: %.2f" % (time.time() - time1))
+	def write_geometries(objects):
+		fw("geometries = {\n")
+		for o in objects:
+			if o.type == 'MESH': write_mesh(o, o.name)
+		fw("}\n")
 
+	write_geometries(objects)
 
 def _write(context, filepath,
-			  EXPORT_TRI,  # ok
-			  EXPORT_NORMALS,  # not yet
-			  EXPORT_UV,  # ok
-			  EXPORT_APPLY_MODIFIERS,  # ok
-			  EXPORT_KEEP_VERT_ORDER,
-			  EXPORT_SEL_ONLY,  # ok
-			  EXPORT_ANIMATION,
-			  EXPORT_GLOBAL_MATRIX,
-			  ):  # Not used
-
-	base_name, ext = os.path.splitext(filepath)
-	context_name = [base_name, '', '', ext]  # Base name, scene name, frame number, extension
+	EXPORT_TRI,
+	EXPORT_NORMALS,
+	EXPORT_UV,
+	EXPORT_APPLY_MODIFIERS,
+	EXPORT_SEL_ONLY,
+	EXPORT_GLOBAL_MATRIX,
+	):
 
 	scene = context.scene
 
@@ -320,72 +167,38 @@ def _write(context, filepath,
 	if bpy.ops.object.mode_set.poll():
 		bpy.ops.object.mode_set(mode='OBJECT')
 
-	orig_frame = scene.frame_current
-
-	# Export an animation?
-	if EXPORT_ANIMATION:
-		scene_frames = range(scene.frame_start, scene.frame_end + 1)  # Up to and including the end frame.
+	if EXPORT_SEL_ONLY:
+		objects = context.selected_objects
 	else:
-		scene_frames = [orig_frame]  # Dont export an animation.
-
-	# Loop through all frames in the scene and export.
-	for frame in scene_frames:
-		if EXPORT_ANIMATION:  # Add frame to the filepath.
-			context_name[2] = '_%.6d' % frame
-
-		scene.frame_set(frame, 0.0)
-		if EXPORT_SEL_ONLY:
-			objects = context.selected_objects
-		else:
-			objects = scene.objects
-
-		full_path = ''.join(context_name)
-
-		# erm... bit of a problem here, this can overwrite files when exporting frames. not too bad.
-		# EXPORT THE FILE.
-		write_file(full_path, objects, scene,
-				   EXPORT_TRI,
-				   EXPORT_NORMALS,
-				   EXPORT_UV,
-				   EXPORT_APPLY_MODIFIERS,
-				   EXPORT_KEEP_VERT_ORDER,
-				   EXPORT_GLOBAL_MATRIX,
-				   )
-
-	scene.frame_set(orig_frame, 0.0)
-
-	# Restore old active scene.
-#   orig_scene.makeCurrent()
-#   Window.WaitCursor(0)
-
-
-"""
-Currently the exporter lacks these features:
-* multiple scene export (only active scene is written)
-* particles
-"""
-
+		objects = scene.objects
+
+	f = open(filepath, "wb")
+	write_file(f, objects, scene,
+		EXPORT_TRI,
+		EXPORT_NORMALS,
+		EXPORT_UV,
+		EXPORT_APPLY_MODIFIERS,
+		EXPORT_GLOBAL_MATRIX,
+	)
+	f.close()
 
 def save(operator, context, filepath="",
-		 use_triangles=False,
-		 use_normals=False,
-		 use_uvs=True,
-		 use_mesh_modifiers=True,
-		 keep_vertex_order=False,
-		 use_selection=True,
-		 use_animation=False,
-		 global_matrix=None,
-		 ):
+	use_triangles=False,
+	use_normals=False,
+	use_uvs=True,
+	use_mesh_modifiers=True,
+	use_selection=True,
+	use_animation=False,
+	global_matrix=None,
+	):
 
 	_write(context, filepath,
-		   EXPORT_TRI=use_triangles,
-		   EXPORT_NORMALS=use_normals,
-		   EXPORT_UV=use_uvs,
-		   EXPORT_APPLY_MODIFIERS=use_mesh_modifiers,
-		   EXPORT_KEEP_VERT_ORDER=keep_vertex_order,
-		   EXPORT_SEL_ONLY=use_selection,
-		   EXPORT_ANIMATION=use_animation,
-		   EXPORT_GLOBAL_MATRIX=global_matrix,
-		   )
+		EXPORT_TRI=use_triangles,
+		EXPORT_NORMALS=use_normals,
+		EXPORT_UV=use_uvs,
+		EXPORT_APPLY_MODIFIERS=use_mesh_modifiers,
+		EXPORT_SEL_ONLY=use_selection,
+		EXPORT_GLOBAL_MATRIX=global_matrix,
+		)
 
 	return {'FINISHED'}

+ 21 - 25
src/core/containers/array.h

@@ -122,11 +122,11 @@ namespace array
 
 		if (capacity > 0)
 		{
-			T* tmp = a._array;
+			T* tmp = a._data;
 			a._capacity = capacity;
-			a._array = (T*)a._allocator->allocate(capacity * sizeof(T), CE_ALIGNOF(T));
+			a._data = (T*)a._allocator->allocate(capacity * sizeof(T), CE_ALIGNOF(T));
 
-			memcpy(a._array, tmp, a._size * sizeof(T));
+			memcpy(a._data, tmp, a._size * sizeof(T));
 
 			if (tmp)
 				a._allocator->deallocate(tmp);
@@ -156,7 +156,7 @@ namespace array
 		if (a._capacity == a._size)
 			grow(a, 0);
 
-		a._array[a._size] = item;
+		a._data[a._size] = item;
 
 		return a._size++;
 	}
@@ -175,7 +175,7 @@ namespace array
 		if (a._capacity <= a._size + count)
 			grow(a, a._size + count);
 
-		memcpy(&a._array[a._size], items, sizeof(T) * count);
+		memcpy(&a._data[a._size], items, sizeof(T) * count);
 		a._size += count;
 
 		return a._size;
@@ -190,57 +190,53 @@ namespace array
 	template <typename T>
 	inline const T* begin(const Array<T>& a)
 	{
-		return a._array;
+		return a._data;
 	}
 
 	template <typename T>
 	inline T* begin(Array<T>& a)
 	{
-		return a._array;
+		return a._data;
 	}
 
 	template <typename T>
 	inline const T* end(const Array<T>& a)
 	{
-		return a._array + a._size;
+		return a._data + a._size;
 	}
 
 	template <typename T>
 	inline T* end(Array<T>& a)
 	{
-		return a._array + a._size;
+		return a._data + a._size;
 	}
 
 	template <typename T>
 	inline T& front(Array<T>& a)
 	{
 		CE_ASSERT(a._size > 0, "The array is empty");
-
-		return a._array[0];
+		return a._data[0];
 	}
 
 	template <typename T>
 	inline const T& front(const Array<T>& a)
 	{
 		CE_ASSERT(a._size > 0, "The array is empty");
-
-		return a._array[0];
+		return a._data[0];
 	}
 
 	template <typename T>
 	inline T& back(Array<T>& a)
 	{
 		CE_ASSERT(a._size > 0, "The array is empty");
-
-		return a._array[a._size - 1];
+		return a._data[a._size - 1];
 	}
 
 	template <typename T>
 	inline const T& back(const Array<T>& a)
 	{
 		CE_ASSERT(a._size > 0, "The array is empty");
-
-		return a._array[a._size - 1];
+		return a._data[a._size - 1];
 	}
 } // namespace array
 
@@ -249,7 +245,7 @@ inline Array<T>::Array(Allocator& a)
 	: _allocator(&a)
 	, _capacity(0)
 	, _size(0)
-	, _array(NULL)
+	, _data(NULL)
 {
 }
 
@@ -258,7 +254,7 @@ inline Array<T>::Array(Allocator& a, uint32_t capacity)
 	: _allocator(&a)
 	, _capacity(0)
 	, _size(0)
-	, _array(NULL)
+	, _data(NULL)
 {
 	array::resize(*this, capacity);
 }
@@ -268,7 +264,7 @@ inline Array<T>::Array(const Array<T>& other)
 	: _allocator(other._allocator)
 	, _capacity(0)
 	, _size(0)
-	, _array(NULL)
+	, _data(NULL)
 {
 	*this = other;
 }
@@ -276,8 +272,8 @@ inline Array<T>::Array(const Array<T>& other)
 template <typename T>
 inline Array<T>::~Array()
 {
-	if (_array)
-		_allocator->deallocate(_array);
+	if (_data)
+		_allocator->deallocate(_data);
 }
 
 template <typename T>
@@ -285,7 +281,7 @@ inline T& Array<T>::operator[](uint32_t index)
 {
 	CE_ASSERT(index < _size, "Index out of bounds");
 
-	return _array[index];
+	return _data[index];
 }
 
 template <typename T>
@@ -293,7 +289,7 @@ inline const T& Array<T>::operator[](uint32_t index) const
 {
 	CE_ASSERT(index < _size, "Index out of bounds");
 
-	return _array[index];
+	return _data[index];
 }
 
 template <typename T>
@@ -301,7 +297,7 @@ inline Array<T>& Array<T>::operator=(const Array<T>& other)
 {
 	const uint32_t size = other._size;
 	array::resize(*this, size);
-	memcpy(_array, other._array, sizeof(T) * size);
+	memcpy(_data, other._data, sizeof(T) * size);
 	return *this;
 }
 

+ 7 - 7
src/core/containers/container_types.h

@@ -22,10 +22,10 @@ namespace crown
 template <typename T>
 struct Array
 {
-	Array(Allocator& allocator);
+	Array(Allocator& a);
 
 	/// Allocates capacity * sizeof(T) bytes.
-	Array(Allocator& allocator, uint32_t capacity);
+	Array(Allocator& a, uint32_t capacity);
 	Array(const Array<T>& other);
 	~Array();
 
@@ -38,7 +38,7 @@ struct Array
 	Allocator* _allocator;
 	uint32_t _capacity;
 	uint32_t _size;
-	T* _array;
+	T* _data;
 };
 
 /// Dynamic array of objects.
@@ -50,8 +50,8 @@ struct Array
 template <typename T>
 struct Vector
 {
-	Vector(Allocator& allocator);
-	Vector(Allocator& allocator, uint32_t capacity);
+	Vector(Allocator& a);
+	Vector(Allocator& a, uint32_t capacity);
 	Vector(const Vector<T>& other);
 	~Vector();
 
@@ -64,7 +64,7 @@ struct Vector
 	Allocator* _allocator;
 	uint32_t _capacity;
 	uint32_t _size;
-	T* _array;
+	T* _data;
 };
 
 /// Circular buffer double-ended queue of POD items.
@@ -75,7 +75,7 @@ struct Vector
 template <typename T>
 struct Queue
 {
-	Queue(Allocator& allocator);
+	Queue(Allocator& a);
 
 	/// Random access by index
 	T& operator[](uint32_t index);

+ 4 - 21
src/core/containers/queue.h

@@ -106,7 +106,6 @@ namespace queue
 		if (q._read + q._size > old_size)
 		{
 			memmove(array::begin(q._queue) + capacity - (old_size - q._read), array::begin(q._queue) + q._read, (old_size - q._read) * sizeof(T));
-
 			q._read += (capacity - old_size);
 		}
 	}
@@ -117,9 +116,7 @@ namespace queue
 		uint32_t new_capacity = array::size(q._queue) * 2 + 1;
 
 		if (new_capacity < min_capacity)
-		{
 			new_capacity = min_capacity;
-		}
 
 		increase_capacity(q, new_capacity);
 	}
@@ -128,9 +125,7 @@ namespace queue
 	inline void push_back(Queue<T>& q, const T& item)
 	{
 		if (space(q) == 0)
-		{
 			grow(q, 0);
-		}
 
 		q[q._size] = item;
 
@@ -149,9 +144,7 @@ namespace queue
 	inline void push_front(Queue<T>& q, const T& item)
 	{
 		if (space(q) == 0)
-		{
 			grow(q, 0);
-		}
 
 		q._read = (q._read - 1 + array::size(q._queue)) % array::size(q._queue);
 
@@ -173,18 +166,14 @@ namespace queue
 	inline void push(Queue<T>& q, const T *items, uint32_t n)
 	{
 		if (q.space() < n)
-		{
 			q.grow(q.size() + n);
-		}
 
 		const uint32_t size = array::size(q._queue);
 		const uint32_t insert = (q._read + q._size) % size;
 
 		uint32_t to_insert = n;
 		if (insert + to_insert > size)
-		{
 			to_insert = size - insert;
-		}
 
 		memcpy(array::begin(q._queue) + insert, items, to_insert * sizeof(T));
 
@@ -227,16 +216,14 @@ namespace queue
 	template <typename T>
 	inline T* end(Queue<T>& q)
 	{
-		uint32_t end = q._read + q._size;
-
+		const uint32_t end = q._read + q._size;
 		return end >= array::size(q._queue) ? array::end(q._queue) : array::begin(q._queue) + end;
 	}
 
 	template <typename T>
 	inline const T* end(const Queue<T>& q)
 	{
-		uint32_t end = q._read + q._size;
-
+		const uint32_t end = q._read + q._size;
 		return end >= array::size(q._queue) ? array::end(q._queue) : array::begin(q._queue) + end;
 	}
 
@@ -244,7 +231,6 @@ namespace queue
 	inline T& front(Queue<T>& q)
 	{
 		CE_ASSERT(q._size > 0, "The queue is empty");
-
 		return q._queue[q._read];
 	}
 
@@ -252,7 +238,6 @@ namespace queue
 	inline const T& front(const Queue<T>& q)
 	{
 		CE_ASSERT(q._size > 0, "The queue is empty");
-
 		return q._queue[q._read];
 	}
 
@@ -260,7 +245,6 @@ namespace queue
 	inline T& back(Queue<T>& q)
 	{
 		CE_ASSERT(q._size > 0, "The queue is empty");
-
 		return q[q._size - 1];
 	}
 
@@ -268,17 +252,16 @@ namespace queue
 	inline const T& back(const Queue<T>& q)
 	{
 		CE_ASSERT(q._size > 0, "The queue is empty");
-
 		return q[q._size - 1];
 	}
 
 } // namespace queue
 
 template <typename T>
-inline Queue<T>::Queue(Allocator& allocator)
+inline Queue<T>::Queue(Allocator& a)
 	: _read(0)
 	, _size(0)
-	, _queue(allocator)
+	, _queue(a)
 {
 }
 

+ 24 - 36
src/core/containers/vector.h

@@ -120,13 +120,13 @@ namespace vector
 
 		if (capacity > 0)
 		{
-			T* tmp = v._array;
+			T* tmp = v._data;
 			v._capacity = capacity;
-			v._array = (T*)v._allocator->allocate(capacity * sizeof(T), CE_ALIGNOF(T));
+			v._data = (T*)v._allocator->allocate(capacity * sizeof(T), CE_ALIGNOF(T));
 
 			for (uint32_t i = 0; i < v._size; i++)
 			{
-				new (v._array + i) T(tmp[i]);
+				new (v._data + i) T(tmp[i]);
 			}
 
 			if (tmp)
@@ -163,7 +163,7 @@ namespace vector
 		if (v._capacity == v._size)
 			grow(v, 0);
 
-		new (v._array + v._size) T(item);
+		new (v._data + v._size) T(item);
 
 		return v._size++;
 	}
@@ -173,7 +173,7 @@ namespace vector
 	{
 		CE_ASSERT(v._size > 0, "The vector is empty");
 
-		v._array[v._size - 1].~T();
+		v._data[v._size - 1].~T();
 		--v._size;
 	}
 
@@ -183,11 +183,9 @@ namespace vector
 		if (v._capacity <= v._size + count)
 			grow(v, v._size + count);
 
-		T* arr = &v._array[v._size];
+		T* arr = &v._data[v._size];
 		for (uint32_t i = 0; i < count; i++)
-		{
 			arr[i] = items[i];
-		}
 
 		v._size += count;
 		return v._size;
@@ -197,9 +195,7 @@ namespace vector
 	inline void clear(Vector<T>& v)
 	{
 		for (uint32_t i = 0; i < v._size; i++)
-		{
-			v._array[i].~T();
-		}
+			v._data[i].~T();
 
 		v._size = 0;
 	}
@@ -207,57 +203,53 @@ namespace vector
 	template <typename T>
 	inline T* begin(Vector<T>& v)
 	{
-		return v._array;
+		return v._data;
 	}
 
 	template <typename T>
 	inline const T* begin(const Vector<T>& v)
 	{
-		return v._array;
+		return v._data;
 	}
 
 	template <typename T>
 	inline T* end(Vector<T>& v)
 	{
-		return v._array + v._size;
+		return v._data + v._size;
 	}
 
 	template <typename T>
 	inline const T* end(const Vector<T>& v)
 	{
-		return v._array + v._size;
+		return v._data + v._size;
 	}
 
 	template <typename T>
 	inline T& front(Vector<T>& v)
 	{
 		CE_ASSERT(v._size > 0, "The vector is empty");
-
-		return v._array[0];
+		return v._data[0];
 	}
 
 	template <typename T>
 	inline const T& front(const Vector<T>& v)
 	{
 		CE_ASSERT(v._size > 0, "The vector is empty");
-
-		return v._array[0];
+		return v._data[0];
 	}
 
 	template <typename T>
 	inline T& back(Vector<T>& v)
 	{
 		CE_ASSERT(v._size > 0, "The vector is empty");
-
-		return v._array[v._size - 1];
+		return v._data[v._size - 1];
 	}
 
 	template <typename T>
 	inline const T& back(const Vector<T>& v)
 	{
 		CE_ASSERT(v._size > 0, "The vector is empty");
-
-		return v._array[v._size - 1];
+		return v._data[v._size - 1];
 	}
 } // namespace vector
 
@@ -266,7 +258,7 @@ inline Vector<T>::Vector(Allocator& a)
 	: _allocator(&a)
 	, _capacity(0)
 	, _size(0)
-	, _array(NULL)
+	, _data(NULL)
 {
 }
 
@@ -275,7 +267,7 @@ inline Vector<T>::Vector(Allocator& a, uint32_t capacity)
 	: _allocator(&a)
 	, _capacity(0)
 	, _size(0)
-	, _array(NULL)
+	, _data(NULL)
 {
 	vector::resize(*this, capacity);
 }
@@ -285,7 +277,7 @@ inline Vector<T>::Vector(const Vector<T>& other)
 	: _allocator(other._allocator)
 	, _capacity(0)
 	, _size(0)
-	, _array(NULL)
+	, _data(NULL)
 {
 	*this = other;
 }
@@ -294,12 +286,10 @@ template <typename T>
 inline Vector<T>::~Vector()
 {
 	for (uint32_t i = 0; i < _size; i++)
-	{
-		_array[i].~T();
-	}
+		_data[i].~T();
 
-	if (_array)
-		_allocator->deallocate(_array);
+	if (_data)
+		_allocator->deallocate(_data);
 }
 
 template <typename T>
@@ -307,7 +297,7 @@ inline T& Vector<T>::operator[](uint32_t index)
 {
 	CE_ASSERT(index < _size, "Index out of bounds");
 
-	return _array[index];
+	return _data[index];
 }
 
 template <typename T>
@@ -315,7 +305,7 @@ inline const T& Vector<T>::operator[](uint32_t index) const
 {
 	CE_ASSERT(index < _size, "Index out of bounds");
 
-	return _array[index];
+	return _data[index];
 }
 
 template <typename T>
@@ -325,9 +315,7 @@ inline const Vector<T>& Vector<T>::operator=(const Vector<T>& other)
 	vector::resize(*this, size);
 
 	for (uint32_t i = 0; i < size; i++)
-	{
-		_array[i] = other._array[i];
-	}
+		_data[i] = other._data[i];
 
 	return *this;
 }

+ 19 - 6
src/core/json/njson.cpp

@@ -65,9 +65,23 @@ namespace njson
 
 		if (*json == '/')
 		{
-			json = next(json, '/');
-			json = next(json, '/');
-			while (*json && *json != '\n') json = next(json);
+			json = next(json);
+			if (*json == '/')
+			{
+				json = next(json, '/');
+				while (*json && *json != '\n')
+					json = next(json);
+			}
+			else if (*json == '*')
+			{
+				json = next(json);
+				while (*json && *json != '*')
+					json = next(json);
+				json = next(json, '*');
+				json = next(json, '/');
+			}
+			else
+				CE_FATAL("Bad comment");
 		}
 
 		return json;
@@ -299,8 +313,6 @@ namespace njson
 	{
 		CE_ASSERT_NOT_NULL(json);
 
-		json = skip_spaces(json);
-
 		while (*json)
 		{
 			DynamicString key;
@@ -312,7 +324,6 @@ namespace njson
 
 			map::set(object, key, json);
 
-			const char* tmp = json;
 			json = skip_value(json);
 			json = skip_spaces(json);
 		}
@@ -365,6 +376,8 @@ namespace njson
 	{
 		CE_ASSERT_NOT_NULL(json);
 
+		json = skip_spaces(json);
+
 		if (*json == '{')
 			parse_object(json, object);
 		else

+ 0 - 4
src/core/os.h

@@ -14,14 +14,10 @@
 #include "temp_allocator.h"
 
 #if CROWN_PLATFORM_POSIX
-	#include <cstdarg>
-	#include <cstdio>
-	#include <cstdlib>
 	#include <dirent.h>
 	#include <dlfcn.h>
 	#include <sys/stat.h>
 	#include <sys/time.h>
-	#include <sys/types.h>
 	#include <sys/wait.h>
 	#include <errno.h>
 	#include <time.h>

+ 0 - 1
src/core/os_event_queue.h

@@ -5,7 +5,6 @@
 
 #pragma once
 
-#include <cstring>
 #include "types.h"
 #include "mouse.h"
 #include "keyboard.h"

+ 1 - 1
src/device.cpp

@@ -70,7 +70,7 @@ void Device::init()
 	_boot_package->load();
 	_boot_package->flush();
 
-	_lua_environment->execute((LuaResource*)_resource_manager->get(LUA_TYPE, _boot_script_id));
+	_lua_environment->execute((LuaResource*)_resource_manager->get(SCRIPT_TYPE, _boot_script_id));
 	_lua_environment->call_global("init", 0);
 }
 

+ 5 - 1
src/lua/lua_environment.cpp

@@ -74,7 +74,7 @@ static int require(lua_State* L)
 {
 	using namespace lua_resource;
 	LuaStack stack(L);
-	const LuaResource* lr = (LuaResource*)device()->resource_manager()->get(LUA_TYPE, stack.get_resource_id(1));
+	const LuaResource* lr = (LuaResource*)device()->resource_manager()->get(SCRIPT_TYPE, stack.get_resource_id(1));
 	luaL_loadbuffer(L, program(lr), size(lr), "");
 	return 1;
 }
@@ -174,6 +174,8 @@ LuaEnvironment::~LuaEnvironment()
 
 void LuaEnvironment::load_libs()
 {
+	lua_gc(L, LUA_GCSTOP, 0);
+
 	// Open default libraries
 	luaL_openlibs(L);
 
@@ -250,6 +252,8 @@ void LuaEnvironment::load_libs()
 
 	// Ensure stack is clean
 	CE_ASSERT(lua_gettop(L) == 0, "Stack not clean");
+
+	lua_gc(L, LUA_GCRESTART, 0);
 }
 
 void LuaEnvironment::execute(const LuaResource* lr)

+ 1 - 3
src/resource/font_resource.cpp

@@ -28,8 +28,6 @@ namespace font_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -50,7 +48,7 @@ namespace font_resource
 		}
 
 		FontResource fr;
-		fr.version = VERSION;
+		fr.version = FONT_VERSION;
 		fr.num_glyphs = array::size(m_glyphs);
 		fr.texture_size = size.to_int();
 		fr.font_size = font_size.to_int();

+ 1 - 3
src/resource/level_resource.cpp

@@ -175,8 +175,6 @@ namespace level_resource
 {
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -215,7 +213,7 @@ namespace level_resource
 		}
 
 		LevelResource lr;
-		lr.version = VERSION;
+		lr.version = LEVEL_VERSION;
 		lr.num_units = array::size(units);
 		lr.num_sounds = array::size(sounds);
 

+ 1 - 3
src/resource/lua_resource.cpp

@@ -23,8 +23,6 @@ namespace lua_resource
 {
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		TempAllocator1024 alloc;
 		DynamicString res_abs_path(alloc);
 		TempAllocator1024 alloc2;
@@ -52,7 +50,7 @@ namespace lua_resource
 		opts.delete_file(bc_abs_path.c_str());
 
 		LuaResource lr;
-		lr.version = VERSION;
+		lr.version = SCRIPT_VERSION;
 		lr.size = array::size(blob);
 
 		opts.write(lr.version);

+ 1 - 3
src/resource/material_resource.cpp

@@ -147,8 +147,6 @@ namespace material_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -163,7 +161,7 @@ namespace material_resource
 		parse_uniforms(root, unidata, names, dynblob);
 
 		MaterialResource mr;
-		mr.version = VERSION;
+		mr.version = MATERIAL_VERSION;
 		mr.shader = shader;
 		mr.num_textures = array::size(texdata);
 		mr.texture_data_offset = sizeof(mr);

+ 1 - 3
src/resource/mesh_resource.cpp

@@ -33,8 +33,6 @@ namespace mesh_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -148,7 +146,7 @@ namespace mesh_resource
 		decl.end();
 
 		// Write
-		opts.write(VERSION);
+		opts.write(MESH_VERSION);
 		opts.write(decl);
 		opts.write(array::size(vertices));
 		for (uint32_t i = 0; i < array::size(vertices); ++i)

+ 1 - 3
src/resource/package_resource.cpp

@@ -17,8 +17,6 @@ namespace package_resource
 {
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -52,7 +50,7 @@ namespace package_resource
 		const uint32_t num_sprite_animations = sprite_animation.is_nil() ? 0 : sprite_animation.size();
 
 		// Write header
-		opts.write(VERSION);
+		opts.write(PACKAGE_VERSION);
 		opts.write(num_textures);
 		uint32_t offt = sizeof(PackageResource);
 		opts.write(offt);

+ 2 - 6
src/resource/physics_resource.cpp

@@ -221,8 +221,6 @@ namespace physics_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -250,7 +248,7 @@ namespace physics_resource
 		if (root.has_key("actors")) parse_actors(root.key("actors"), m_actors);
 		if (root.has_key("joints")) parse_joints(root.key("joints"), m_joints);
 		PhysicsResource pr;
-		pr.version = VERSION;
+		pr.version = PHYSICS_VERSION;
 		pr.num_controllers = m_has_controller ? 1 : 0;
 		pr.num_colliders = array::size(m_shapes);
 		pr.num_actors = array::size(m_actors);
@@ -573,8 +571,6 @@ namespace physics_config_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -605,7 +601,7 @@ namespace physics_config_resource
 
 		// Setup struct for writing
 		PhysicsConfigResource pcr;
-		pcr.version = VERSION;
+		pcr.version = PHYSICS_CONFIG_VERSION;
 		pcr.num_materials = array::size(material_names);
 		pcr.num_shapes = array::size(shape_names);
 		pcr.num_actors = array::size(actor_names);

+ 3 - 3
src/resource/resource_package.h

@@ -45,7 +45,7 @@ struct ResourcePackage
 
 		for (uint32_t i = 0; i < num_scripts(_package); i++)
 		{
-			_resman->load(LUA_TYPE, get_script_id(_package, i));
+			_resman->load(SCRIPT_TYPE, get_script_id(_package, i));
 		}
 
 		for (uint32_t i = 0; i < num_sounds(_package); i++)
@@ -166,7 +166,7 @@ struct ResourcePackage
 
 		for (uint32_t i = 0; i < num_scripts(_package); i++)
 		{
-			_resman->unload(LUA_TYPE, get_script_id(_package, i));
+			_resman->unload(SCRIPT_TYPE, get_script_id(_package, i));
 		}
 
 		for (uint32_t i = 0; i < num_textures(_package); i++)
@@ -194,7 +194,7 @@ struct ResourcePackage
 
 		for (uint32_t i = 0; i < num_scripts(_package); i++)
 		{
-			if (!_resman->can_get(LUA_TYPE, get_script_id(_package, i)))
+			if (!_resman->can_get(SCRIPT_TYPE, get_script_id(_package, i)))
 				return false;
 		}
 

+ 1 - 1
src/resource/resource_registry.cpp

@@ -56,7 +56,7 @@ struct ResourceCallback
 
 static const ResourceCallback RESOURCE_CALLBACK_REGISTRY[] =
 {
-	{ LUA_TYPE,              lur::compile, lur::load, lur::unload, lur::online, lur::offline },
+	{ SCRIPT_TYPE,           lur::compile, lur::load, lur::unload, lur::online, lur::offline },
 	{ TEXTURE_TYPE,          txr::compile, txr::load, txr::unload, txr::online, txr::offline },
 	{ MESH_TYPE,             mhr::compile, mhr::load, mhr::unload, mhr::online, mhr::offline },
 	{ SOUND_TYPE,            sdr::compile, sdr::load, sdr::unload, sdr::online, sdr::offline },

+ 16 - 16
src/resource/resource_types.h

@@ -7,7 +7,7 @@
 
 #define FONT_EXTENSION             "font"
 #define LEVEL_EXTENSION            "level"
-#define LUA_EXTENSION              "lua"
+#define SCRIPT_EXTENSION           "lua"
 #define MATERIAL_EXTENSION         "material"
 #define MESH_EXTENSION             "mesh"
 #define PACKAGE_EXTENSION          "package"
@@ -22,7 +22,7 @@
 
 #define FONT_TYPE                  StringId64(0x9efe0a916aae7880)
 #define LEVEL_TYPE                 StringId64(0x2a690fd348fe9ac5)
-#define LUA_TYPE                   StringId64(0xa14e8dfa2cd117e2)
+#define SCRIPT_TYPE                StringId64(0xa14e8dfa2cd117e2)
 #define MATERIAL_TYPE              StringId64(0xeac0b497876adedf)
 #define MESH_TYPE                  StringId64(0x48ff313713a997a1)
 #define PACKAGE_TYPE               StringId64(0xad9c6d9ed1e5e77a)
@@ -35,20 +35,20 @@
 #define TEXTURE_TYPE               StringId64(0xcd4238c6a0c69e32)
 #define UNIT_TYPE                  StringId64(0xe0a48d0be9a7453f)
 
-// #define FONT_VERSION               uint32_t(1)
-// #define LEVEL_VERSION              uint32_t(1)
-// #define LUA_VERSION                uint32_t(1)
-// #define MATERIAL_VERSION           uint32_t(1)
-// #define MESH_VERSION               uint32_t(1)
-// #define PACKAGE_VERSION            uint32_t(1)
-// #define PHYSICS_CONFIG_VERSION     uint32_t(1)
-// #define PHYSICS_VERSION            uint32_t(1)
-// #define SHADER_VERSION             uint32_t(1)
-// #define SOUND_VERSION              uint32_t(1)
-// #define SPRITE_ANIMATION_VERSION   uint32_t(1)
-// #define SPRITE_VERSION             uint32_t(1)
-// #define TEXTURE_VERSION            uint32_t(1)
-// #define UNIT_VERSION               uint32_t(1)
+#define FONT_VERSION               uint32_t(1)
+#define LEVEL_VERSION              uint32_t(1)
+#define SCRIPT_VERSION             uint32_t(1)
+#define MATERIAL_VERSION           uint32_t(1)
+#define MESH_VERSION               uint32_t(1)
+#define PACKAGE_VERSION            uint32_t(1)
+#define PHYSICS_CONFIG_VERSION     uint32_t(1)
+#define PHYSICS_VERSION            uint32_t(1)
+#define SHADER_VERSION             uint32_t(1)
+#define SOUND_VERSION              uint32_t(1)
+#define SPRITE_ANIMATION_VERSION   uint32_t(1)
+#define SPRITE_VERSION             uint32_t(1)
+#define TEXTURE_VERSION            uint32_t(1)
+#define UNIT_VERSION               uint32_t(1)
 
 namespace crown
 {

+ 1 - 3
src/resource/sound_resource.cpp

@@ -32,8 +32,6 @@ namespace sound_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -47,7 +45,7 @@ namespace sound_resource
 
 		// Write
 		SoundResource sr;
-		sr.version = VERSION;
+		sr.version = SOUND_VERSION;
 		sr.size = wav->data_size;
 		sr.sample_rate = wav->fmt_sample_rate;
 		sr.avg_bytes_ps = wav->fmt_avarage;

+ 2 - 6
src/resource/sprite_resource.cpp

@@ -43,8 +43,6 @@ namespace sprite_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -102,7 +100,7 @@ namespace sprite_resource
 		const uint32_t num_indices = array::size(indices);
 
 		// Write header
-		opts.write(VERSION);
+		opts.write(SPRITE_VERSION);
 
 		opts.write(num_vertices);
 		for (uint32_t i = 0; i < array::size(vertices); i++)
@@ -198,8 +196,6 @@ namespace sprite_animation_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -211,7 +207,7 @@ namespace sprite_animation_resource
 		parse_animations(root, anim_names, anim_data, anim_frames);
 
 		SpriteAnimationResource sar;
-		sar.version = VERSION;
+		sar.version = SPRITE_ANIMATION_VERSION;
 		sar.num_animations = array::size(anim_names);
 		sar.num_frames = array::size(anim_frames);
 		sar.frames_offset = uint32_t(sizeof(SpriteAnimationResource) +

+ 1 - 3
src/resource/texture_resource.cpp

@@ -558,8 +558,6 @@ namespace texture_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -595,7 +593,7 @@ namespace texture_resource
 		opts._fs.close(source);
 
 		// Write DDS
-		opts.write(VERSION); // Version
+		opts.write(TEXTURE_VERSION); // Version
 		opts.write(uint32_t(0)); // Size
 		write_dds(opts._bw, image);
 

+ 1 - 3
src/resource/unit_resource.cpp

@@ -239,8 +239,6 @@ namespace unit_resource
 
 	void compile(const char* path, CompileOptions& opts)
 	{
-		static const uint32_t VERSION = 1;
-
 		Buffer buf = opts.read(path);
 		JSONParser json(buf);
 		JSONElement root = json.root();
@@ -285,7 +283,7 @@ namespace unit_resource
 			sprite_anim = root.key("sprite_animation").to_resource_id();
 
 		UnitResource ur;
-		ur.version = VERSION;
+		ur.version = UNIT_VERSION;
 		ur.name = StringId64(unit_name.c_str());
 		ur.physics_resource = m_physics_resource;
 		ur.sprite_animation = sprite_anim;