From 837c7f6693e72865acd21c4bab506200ca442b54 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 13 Jun 2015 21:22:16 -0400 Subject: [PATCH] Implement SDL exclude/volatile states --- korman/exporter/convert.py | 3 + korman/properties/prop_object.py | 95 +++++++++++++++++++++++++------- korman/ui/ui_object.py | 8 +-- 3 files changed, 81 insertions(+), 25 deletions(-) diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index 4d3dfa6..7e11520 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -157,6 +157,9 @@ class Exporter: print(" Exporting '{}' modifier as '{}'".format(mod.bl_label, mod.display_name)) mod.export(self, bl_obj, sceneobject) + # Last, but not least, apply synch settings + bl_obj.plasma_net.export(bl_obj, sceneobject) + def _export_empty_blobj(self, so, bo): # We don't need to do anything here. This function just makes sure we don't error out # or add a silly special case :( diff --git a/korman/properties/prop_object.py b/korman/properties/prop_object.py index 3a23474..eb41c45 100644 --- a/korman/properties/prop_object.py +++ b/korman/properties/prop_object.py @@ -17,18 +17,6 @@ import bpy from bpy.props import * from PyHSPlasma import * - -def SdlEnumProperty(name): - return bpy.props.EnumProperty(name=name, - description="{} state synchronization".format(name), - items=[ - ("save", "Save to Server", "Save state on the server"), - ("volatile", "Volatile on Server", "Throw away state when the age shuts down"), - ("exclude", "Don't Send to Server", "Don't synchronize with the server"), - ], - default="save") - - class PlasmaObject(bpy.types.PropertyGroup): def _enabled(self, context): # This makes me sad @@ -69,11 +57,80 @@ class PlasmaNet(bpy.types.PropertyGroup): manual_sdl = BoolProperty(name="Override SDL", description="ADVANCED: Manually track high level states on this object", default=False) + sdl_names = set() + + def export(self, bo, so): + volatile, exclude = set(), set() + if self.manual_sdl: + for attr in self.sdl_names: + value = getattr(self, attr) + if value == "volatile": + volatile.add(attr) + elif value == "exclude": + exclude.add(attr) + else: + # Is this a kickable? + if so.sim is not None: + phys = so.sim.object.physical.object + has_kickable = (phys.memberGroup == plSimDefs.kGroupDynamic) + else: + has_kickable = False + + # Is there a PythonFileMod? + for modKey in so.modifiers: + if isinstance(modKey.object, plPythonFileMod): + has_pfm = True + break + else: + has_pfm = False + + # If we have either a kickable or a PFM, the PlasmaMax default is to exclude all the + # logic-type stuff for higher level processing (namely, python) + if has_kickable or has_pfm: + exclude.add("AGMaster") + exclude.add("Layer") + exclude.add("Responder") + exclude.add("Sound") + exclude.add("XRegion") + else: + so.synchFlags |= plSynchedObject.kExcludeAllPersistentState + + # Inspect and apply volatile states, if any + if len(volatile) == len(self.sdl_names): + so.synchFlags |= plSynchedObject.kAllStateIsVolatile + elif volatile: + so.synchFlags |= plSynchedObject.kHasVolatileState + so.volatiles = sorted(volatile) + + # Inspect and apply exclude states, if any + if len(exclude) == len(self.sdl_names): + so.synchFlags |= plSynchedObject.kExcludeAllPersistentState + elif exclude: + so.synchFlags |= plSynchedObject.kExcludePersistentState + so.excludes = sorted(exclude) - # Some of the standard plSynchedObject states - agmaster = SdlEnumProperty("AGMaster") - layer = SdlEnumProperty("Layer") - physical = SdlEnumProperty("Physical") - responder = SdlEnumProperty("Responder") - sound = SdlEnumProperty("Sound") - xregion = SdlEnumProperty("XRegion") + @classmethod + def register(cls): + def SdlEnumProperty(name): + value = bpy.props.EnumProperty(name=name, + description="{} state synchronization".format(name), + items=[ + ("save", "Save to Server", "Save state on the server"), + ("volatile", "Volatile on Server", "Throw away state when the age shuts down"), + ("exclude", "Don't Send to Server", "Don't synchronize with the server"), + ], + default="exclude") + setattr(PlasmaNet, name, value) + PlasmaNet.sdl_names.add(name) + agmaster = SdlEnumProperty("AGMaster") + avatar = SdlEnumProperty("Avatar") + avatar_phys = SdlEnumProperty("AvatarPhysical") + clone = SdlEnumProperty("CloneMessage") + clothing = SdlEnumProperty("Clothing") + layer = SdlEnumProperty("Layer") + morph = SdlEnumProperty("MorphSequence") + particle = SdlEnumProperty("ParticleSystem") + physical = SdlEnumProperty("Physical") + responder = SdlEnumProperty("Responder") + sound = SdlEnumProperty("Sound") + xregion = SdlEnumProperty("XRegion") diff --git a/korman/ui/ui_object.py b/korman/ui/ui_object.py index b0f869b..7b679c2 100644 --- a/korman/ui/ui_object.py +++ b/korman/ui/ui_object.py @@ -70,9 +70,5 @@ class PlasmaNetPanel(ObjectButtonsPanel, bpy.types.Panel): pl_net = context.object.plasma_net layout.active = pl_net.manual_sdl - layout.prop(pl_net, "agmaster", text="Animation") - layout.prop(pl_net, "layer", text="Material") - layout.prop(pl_net, "physical") - layout.prop(pl_net, "responder") - layout.prop(pl_net, "sound") - layout.prop(pl_net, "xregion") + for i in sorted(pl_net.sdl_names): + layout.prop(pl_net, i)