flatten 20260225
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.DS_Store
|
||||
*.pyc
|
||||
xcuserdata
|
||||
.bin
|
||||
624
Core_Graphics.xcodeproj/project.pbxproj
Normal file
624
Core_Graphics.xcodeproj/project.pbxproj
Normal file
@@ -0,0 +1,624 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 55;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
F673E3CE2ADD68AA000281FF /* Screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F673E3CC2ADD68A6000281FF /* Screen.cpp */; };
|
||||
F6C1BAA62CDD4CB9007439C1 /* STB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C1BAA52CDD4C8B007439C1 /* STB.cpp */; };
|
||||
F6C1BAA72CDD4CB9007439C1 /* STB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C1BAA52CDD4C8B007439C1 /* STB.cpp */; };
|
||||
F6C76CC52CDD65E400EC8827 /* Colors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C76CBF2CDD65E000EC8827 /* Colors.cpp */; };
|
||||
F6C76CC62CDD65E500EC8827 /* Colors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C76CBF2CDD65E000EC8827 /* Colors.cpp */; };
|
||||
F6C76CCA2CDD661A00EC8827 /* SDF_deadreckoning.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C76CC72CDD661700EC8827 /* SDF_deadreckoning.cpp */; };
|
||||
F6C76CCB2CDD661A00EC8827 /* SDF_deadreckoning.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C76CC72CDD661700EC8827 /* SDF_deadreckoning.cpp */; };
|
||||
F6C76CCD2CDD67A100EC8827 /* pathfinders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C1BA9D2CDC1616007439C1 /* pathfinders.cpp */; };
|
||||
F6C76CCE2CDD67A200EC8827 /* pathfinders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C1BA9D2CDC1616007439C1 /* pathfinders.cpp */; };
|
||||
F6CA38692933B0B100556E1C /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6CA38682933B09300556E1C /* main.cpp */; };
|
||||
F6D165E52CD819EF00F3967F /* Screen+PNG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6D165E42CD819DA00F3967F /* Screen+PNG.cpp */; };
|
||||
F6D165E62CD819EF00F3967F /* Screen+PNG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6D165E42CD819DA00F3967F /* Screen+PNG.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
F6CA385D2933AD8400556E1C /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
F608ABB328287108005C276B /* libCore_Graphics.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCore_Graphics.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F61F9BF02C6E4DD200F79137 /* Makefile.project */ = {isa = PBXFileReference; lastKnownFileType = text; path = Makefile.project; sourceTree = "<group>"; };
|
||||
F673E3CB2ADD68A5000281FF /* Screen+IO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Screen+IO.h"; sourceTree = "<group>"; };
|
||||
F673E3CC2ADD68A6000281FF /* Screen.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Screen.cpp; sourceTree = "<group>"; };
|
||||
F673E3CD2ADD68A6000281FF /* Screen.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Screen.h; sourceTree = "<group>"; };
|
||||
F673E3CF2ADD6928000281FF /* Screen.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Screen.hpp; sourceTree = "<group>"; };
|
||||
F6971F33282B1184008FBD17 /* libCore_Graphics_iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCore_Graphics_iOS.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F6BF9BE42E390208002E6AF0 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
|
||||
F6C1BA992CDC0556007439C1 /* Screen+erode.inl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Screen+erode.inl"; sourceTree = "<group>"; };
|
||||
F6C1BA9A2CDC0647007439C1 /* Screen+dilate.inl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Screen+dilate.inl"; sourceTree = "<group>"; };
|
||||
F6C1BA9B2CDC15E0007439C1 /* Screen+find_path.inl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Screen+find_path.inl"; sourceTree = "<group>"; };
|
||||
F6C1BA9C2CDC1616007439C1 /* pathfinders.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pathfinders.h; sourceTree = "<group>"; };
|
||||
F6C1BA9D2CDC1616007439C1 /* pathfinders.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = pathfinders.cpp; sourceTree = "<group>"; };
|
||||
F6C1BAA12CDD4C83007439C1 /* STB+TrueType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "STB+TrueType.h"; sourceTree = "<group>"; };
|
||||
F6C1BAA22CDD4C83007439C1 /* STB+Image.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "STB+Image.h"; sourceTree = "<group>"; };
|
||||
F6C1BAA32CDD4C83007439C1 /* STB+TrueType.inl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "STB+TrueType.inl"; sourceTree = "<group>"; };
|
||||
F6C1BAA42CDD4C83007439C1 /* STB+Image.inl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "STB+Image.inl"; sourceTree = "<group>"; };
|
||||
F6C1BAA52CDD4C8B007439C1 /* STB.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = STB.cpp; sourceTree = "<group>"; };
|
||||
F6C76CBF2CDD65E000EC8827 /* Colors.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Colors.cpp; sourceTree = "<group>"; };
|
||||
F6C76CC02CDD65E000EC8827 /* Geometry.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Geometry.hpp; sourceTree = "<group>"; };
|
||||
F6C76CC12CDD65E000EC8827 /* Colors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Colors.h; sourceTree = "<group>"; };
|
||||
F6C76CC22CDD65E000EC8827 /* Geometry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Geometry.h; sourceTree = "<group>"; };
|
||||
F6C76CC32CDD65E000EC8827 /* Color.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Color.hpp; sourceTree = "<group>"; };
|
||||
F6C76CC42CDD65E000EC8827 /* Colors.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Colors.hpp; sourceTree = "<group>"; };
|
||||
F6C76CC72CDD661700EC8827 /* SDF_deadreckoning.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SDF_deadreckoning.cpp; sourceTree = "<group>"; };
|
||||
F6C76CC82CDD661700EC8827 /* SDF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDF.h; sourceTree = "<group>"; };
|
||||
F6C76CC92CDD661700EC8827 /* SDF_deadreckoning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDF_deadreckoning.h; sourceTree = "<group>"; };
|
||||
F6C76CCC2CDD666B00EC8827 /* glm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = glm.h; sourceTree = "<group>"; };
|
||||
F6CA385F2933AD8400556E1C /* Core_Graphics_Tester */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Core_Graphics_Tester; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F6CA38682933B09300556E1C /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
|
||||
F6D1148D2D3DB0E900BFA3B3 /* Screen+and.inl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Screen+and.inl"; sourceTree = "<group>"; };
|
||||
F6D165E32CD8166C00F3967F /* Screen+PNG.inl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Screen+PNG.inl"; sourceTree = "<group>"; };
|
||||
F6D165E42CD819DA00F3967F /* Screen+PNG.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "Screen+PNG.cpp"; sourceTree = "<group>"; };
|
||||
F6DEACD72831C16C0001467D /* Makefile.def */ = {isa = PBXFileReference; lastKnownFileType = text; path = Makefile.def; sourceTree = "<group>"; };
|
||||
F6DEACD82831C16C0001467D /* Makefile.project */ = {isa = PBXFileReference; lastKnownFileType = text; path = Makefile.project; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
F608ABB128287108005C276B /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
F6971F2F282B1184008FBD17 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
F6CA385C2933AD8400556E1C /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
F608ABAA28287108005C276B = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F6CA386A2933B0E600556E1C /* Frameworks */,
|
||||
F6BF9BE42E390208002E6AF0 /* Makefile */,
|
||||
F6DEACD72831C16C0001467D /* Makefile.def */,
|
||||
F6DEACD82831C16C0001467D /* Makefile.project */,
|
||||
F608ABB428287108005C276B /* Products */,
|
||||
F6CA38672933B08A00556E1C /* tests */,
|
||||
F61D7C412E381687002A1AED /* tjp */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F608ABB428287108005C276B /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F608ABB328287108005C276B /* libCore_Graphics.a */,
|
||||
F6971F33282B1184008FBD17 /* libCore_Graphics_iOS.a */,
|
||||
F6CA385F2933AD8400556E1C /* Core_Graphics_Tester */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F608ABBA2828711E005C276B /* core */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F608ABBB2828714B005C276B /* graphics */,
|
||||
);
|
||||
path = core;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F608ABBB2828714B005C276B /* graphics */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F6C76CCC2CDD666B00EC8827 /* glm.h */,
|
||||
F6C76CC72CDD661700EC8827 /* SDF_deadreckoning.cpp */,
|
||||
F6C76CC92CDD661700EC8827 /* SDF_deadreckoning.h */,
|
||||
F6C76CC82CDD661700EC8827 /* SDF.h */,
|
||||
F6C76CC32CDD65E000EC8827 /* Color.hpp */,
|
||||
F6C76CBF2CDD65E000EC8827 /* Colors.cpp */,
|
||||
F6C76CC12CDD65E000EC8827 /* Colors.h */,
|
||||
F6C76CC42CDD65E000EC8827 /* Colors.hpp */,
|
||||
F6C76CC22CDD65E000EC8827 /* Geometry.h */,
|
||||
F6C76CC02CDD65E000EC8827 /* Geometry.hpp */,
|
||||
F61F9BF72C6E516500F79137 /* _tests */,
|
||||
F673E3D02ADD6954000281FF /* soft */,
|
||||
F6C1BAA52CDD4C8B007439C1 /* STB.cpp */,
|
||||
F6C1BAA22CDD4C83007439C1 /* STB+Image.h */,
|
||||
F6C1BAA42CDD4C83007439C1 /* STB+Image.inl */,
|
||||
F6C1BAA12CDD4C83007439C1 /* STB+TrueType.h */,
|
||||
F6C1BAA32CDD4C83007439C1 /* STB+TrueType.inl */,
|
||||
);
|
||||
path = graphics;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F61D7C412E381687002A1AED /* tjp */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F608ABBA2828711E005C276B /* core */,
|
||||
);
|
||||
path = tjp;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F61F9BF72C6E516500F79137 /* _tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
path = _tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F61F9BF82C6E517700F79137 /* _tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F673E3CC2ADD68A6000281FF /* Screen.cpp */,
|
||||
);
|
||||
path = _tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F673E3D02ADD6954000281FF /* soft */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F6C1BA9D2CDC1616007439C1 /* pathfinders.cpp */,
|
||||
F6C1BA9C2CDC1616007439C1 /* pathfinders.h */,
|
||||
F61F9BF82C6E517700F79137 /* _tests */,
|
||||
F673E3CD2ADD68A6000281FF /* Screen.h */,
|
||||
F673E3CF2ADD6928000281FF /* Screen.hpp */,
|
||||
F6C1BA992CDC0556007439C1 /* Screen+erode.inl */,
|
||||
F6D1148D2D3DB0E900BFA3B3 /* Screen+and.inl */,
|
||||
F6C1BA9A2CDC0647007439C1 /* Screen+dilate.inl */,
|
||||
F6C1BA9B2CDC15E0007439C1 /* Screen+find_path.inl */,
|
||||
F6D165E32CD8166C00F3967F /* Screen+PNG.inl */,
|
||||
F6D165E42CD819DA00F3967F /* Screen+PNG.cpp */,
|
||||
F673E3CB2ADD68A5000281FF /* Screen+IO.h */,
|
||||
);
|
||||
path = soft;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F6CA38672933B08A00556E1C /* tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F61F9BF02C6E4DD200F79137 /* Makefile.project */,
|
||||
F6CA38682933B09300556E1C /* main.cpp */,
|
||||
);
|
||||
path = tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F6CA386A2933B0E600556E1C /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
F608ABAF28287108005C276B /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
F6971F2C282B1184008FBD17 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
F608ABB228287108005C276B /* Core_Graphics */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = F608ABB728287108005C276B /* Build configuration list for PBXNativeTarget "Core_Graphics" */;
|
||||
buildPhases = (
|
||||
F608ABAF28287108005C276B /* Headers */,
|
||||
F608ABB028287108005C276B /* Sources */,
|
||||
F608ABB128287108005C276B /* Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = Core_Graphics;
|
||||
productName = Core_Graphics;
|
||||
productReference = F608ABB328287108005C276B /* libCore_Graphics.a */;
|
||||
productType = "com.apple.product-type.library.static";
|
||||
};
|
||||
F6971F2B282B1184008FBD17 /* Core_Graphics_iOS */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = F6971F30282B1184008FBD17 /* Build configuration list for PBXNativeTarget "Core_Graphics_iOS" */;
|
||||
buildPhases = (
|
||||
F6971F2C282B1184008FBD17 /* Headers */,
|
||||
F6971F2D282B1184008FBD17 /* Sources */,
|
||||
F6971F2F282B1184008FBD17 /* Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = Core_Graphics_iOS;
|
||||
productName = Core_Graphics;
|
||||
productReference = F6971F33282B1184008FBD17 /* libCore_Graphics_iOS.a */;
|
||||
productType = "com.apple.product-type.library.static";
|
||||
};
|
||||
F6CA385E2933AD8400556E1C /* Core_Graphics_Tester */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = F6CA38632933AD8400556E1C /* Build configuration list for PBXNativeTarget "Core_Graphics_Tester" */;
|
||||
buildPhases = (
|
||||
F6CA385B2933AD8400556E1C /* Sources */,
|
||||
F6CA385C2933AD8400556E1C /* Frameworks */,
|
||||
F6CA385D2933AD8400556E1C /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = Core_Graphics_Tester;
|
||||
productName = Core_Graphics_Tester;
|
||||
productReference = F6CA385F2933AD8400556E1C /* Core_Graphics_Tester */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
F608ABAB28287108005C276B /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
DefaultBuildSystemTypeForWorkspace = Original;
|
||||
LastSwiftUpdateCheck = 1400;
|
||||
LastUpgradeCheck = 1330;
|
||||
TargetAttributes = {
|
||||
F608ABB228287108005C276B = {
|
||||
CreatedOnToolsVersion = 13.3;
|
||||
};
|
||||
F6CA385E2933AD8400556E1C = {
|
||||
CreatedOnToolsVersion = 14.0;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = F608ABAE28287108005C276B /* Build configuration list for PBXProject "Core_Graphics" */;
|
||||
compatibilityVersion = "Xcode 13.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = F608ABAA28287108005C276B;
|
||||
productRefGroup = F608ABB428287108005C276B /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
F608ABB228287108005C276B /* Core_Graphics */,
|
||||
F6971F2B282B1184008FBD17 /* Core_Graphics_iOS */,
|
||||
F6CA385E2933AD8400556E1C /* Core_Graphics_Tester */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
F608ABB028287108005C276B /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F6C76CCA2CDD661A00EC8827 /* SDF_deadreckoning.cpp in Sources */,
|
||||
F6C76CC52CDD65E400EC8827 /* Colors.cpp in Sources */,
|
||||
F6C76CCD2CDD67A100EC8827 /* pathfinders.cpp in Sources */,
|
||||
F6D165E62CD819EF00F3967F /* Screen+PNG.cpp in Sources */,
|
||||
F6C1BAA62CDD4CB9007439C1 /* STB.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
F6971F2D282B1184008FBD17 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F6C76CCB2CDD661A00EC8827 /* SDF_deadreckoning.cpp in Sources */,
|
||||
F6C76CC62CDD65E500EC8827 /* Colors.cpp in Sources */,
|
||||
F6C76CCE2CDD67A200EC8827 /* pathfinders.cpp in Sources */,
|
||||
F6D165E52CD819EF00F3967F /* Screen+PNG.cpp in Sources */,
|
||||
F6C1BAA72CDD4CB9007439C1 /* STB.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
F6CA385B2933AD8400556E1C /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F673E3CE2ADD68AA000281FF /* Screen.cpp in Sources */,
|
||||
F6CA38692933B0B100556E1C /* main.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
F608ABB528287108005C276B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
GLES_SILENCE_DEPRECATION,
|
||||
GL_SILENCE_DEPRECATION,
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
../Core_IO,
|
||||
../Core_Math,
|
||||
../Core_Misc,
|
||||
../Core_Zero,
|
||||
../Core_Allocator,
|
||||
../Libraries/sdk/Darwin/include,
|
||||
core/graphics/imgui,
|
||||
);
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.6;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
OTHER_LDFLAGS = "-lCore_Zero";
|
||||
SDKROOT = macosx;
|
||||
USE_HEADERMAP = NO;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
F608ABB628287108005C276B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
GLES_SILENCE_DEPRECATION,
|
||||
GL_SILENCE_DEPRECATION,
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
../Core_IO,
|
||||
../Core_Math,
|
||||
../Core_Misc,
|
||||
../Core_Zero,
|
||||
../Core_Allocator,
|
||||
../Libraries/sdk/Darwin/include,
|
||||
core/graphics/imgui,
|
||||
);
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.6;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
OTHER_LDFLAGS = "-lCore_Zero";
|
||||
SDKROOT = macosx;
|
||||
USE_HEADERMAP = NO;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
F608ABB828287108005C276B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T2M28D3T75;
|
||||
EXECUTABLE_PREFIX = lib;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
F608ABB928287108005C276B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T2M28D3T75;
|
||||
EXECUTABLE_PREFIX = lib;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
F6971F31282B1184008FBD17 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T2M28D3T75;
|
||||
EXECUTABLE_PREFIX = lib;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
F6971F32282B1184008FBD17 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T2M28D3T75;
|
||||
EXECUTABLE_PREFIX = lib;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = iphoneos;
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
F6CA38642933AD8400556E1C /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T2M28D3T75;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"${inherited}",
|
||||
../Core_Graphics,
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 12.3;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
F6CA38652933AD8400556E1C /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T2M28D3T75;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"${inherited}",
|
||||
../Core_Graphics,
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 12.3;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
F608ABAE28287108005C276B /* Build configuration list for PBXProject "Core_Graphics" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
F608ABB528287108005C276B /* Debug */,
|
||||
F608ABB628287108005C276B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
F608ABB728287108005C276B /* Build configuration list for PBXNativeTarget "Core_Graphics" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
F608ABB828287108005C276B /* Debug */,
|
||||
F608ABB928287108005C276B /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
F6971F30282B1184008FBD17 /* Build configuration list for PBXNativeTarget "Core_Graphics_iOS" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
F6971F31282B1184008FBD17 /* Debug */,
|
||||
F6971F32282B1184008FBD17 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
F6CA38632933AD8400556E1C /* Build configuration list for PBXNativeTarget "Core_Graphics_Tester" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
F6CA38642933AD8400556E1C /* Debug */,
|
||||
F6CA38652933AD8400556E1C /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = F608ABAB28287108005C276B /* Project object */;
|
||||
}
|
||||
7
Core_Graphics.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
Core_Graphics.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
2
Makefile
Normal file
2
Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
ROOTDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))..)
|
||||
include $(ROOTDIR)/Core_Make/tjp/Make/Makefile
|
||||
6
Makefile.def
Executable file
6
Makefile.def
Executable file
@@ -0,0 +1,6 @@
|
||||
timprepscius.core.include := $(timprepscius.core.include) -I $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
timprepscius.core.link := $(timprepscius.core.link) -L $(dir $(realpath $(lastword $(MAKEFILE_LIST))))/.bin/$(OBJDIR)
|
||||
|
||||
timprepscius.core_graphics.include := $(timprepscius.core_graphics.include) -I $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
timprepscius.core_graphics.link := $(timprepscius.core_graphics.link) -L $(dir $(realpath $(lastword $(MAKEFILE_LIST))))/.bin/$(OBJDIR)
|
||||
|
||||
19
Makefile.project
Executable file
19
Makefile.project
Executable file
@@ -0,0 +1,19 @@
|
||||
include $(MAKEDIR)/Makefile.base
|
||||
|
||||
# use: ls -d tjp/core/*/ tjp/core/*/*/ | rev | cut -c 2- | rev | sed 's/$/ \\/'
|
||||
|
||||
PROJECTS := \
|
||||
tjp/core/graphics \
|
||||
tjp/core/graphics/soft \
|
||||
|
||||
#SRC_PCH := tjp/core/Precompile.pch
|
||||
|
||||
INCPATH := \
|
||||
$(timprepscius.libraries.cpp.include) \
|
||||
$(timprepscius.core.include)
|
||||
|
||||
LIBFILE := libCore_Graphics.a
|
||||
|
||||
COPYTO := $(LIBRARIES_PROJECT)
|
||||
|
||||
include $(MAKEDIR)/Makefile.lib
|
||||
1
tests/Makefile
Symbolic link
1
tests/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../Make/Makefile
|
||||
33
tests/Makefile.project
Executable file
33
tests/Makefile.project
Executable file
@@ -0,0 +1,33 @@
|
||||
include $(MAKEDIR)/Makefile.base
|
||||
|
||||
# use: ls -d core/*/ core/*/*/ | rev | cut -c 2- | rev | sed 's/$/ \\/'
|
||||
|
||||
PROJECTS := \
|
||||
. \
|
||||
../core/graphics/_tests \
|
||||
../core/graphics/soft/_tests \
|
||||
../core/graphics/vuku/_tests \
|
||||
|
||||
INCPATH := \
|
||||
$(timprepscius.libraries.cpp.include) \
|
||||
$(timprepscius.core.include)
|
||||
|
||||
LDPATH := $(timprepscius.libraries.cpp.link)
|
||||
|
||||
LIBS := \
|
||||
-lCore_Zero \
|
||||
-lCore_Misc \
|
||||
-lCore_Math \
|
||||
-lCore_Graphics \
|
||||
-lz_
|
||||
|
||||
EXEFILE := Core_Graphics_Tests.exe
|
||||
|
||||
#COPYTO := $(ROOTDIR)/.bin
|
||||
|
||||
ifeq (Darwin,$(SYS_NAME))
|
||||
LIBS += -lc++
|
||||
endif
|
||||
|
||||
|
||||
include $(MAKEDIR)/Makefile.bin
|
||||
17
tests/main.cpp
Normal file
17
tests/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include <tjp/core/testing/catch.hpp>
|
||||
|
||||
#include <tjp/core/log/Log.h>
|
||||
|
||||
using namespace tjp;
|
||||
using namespace core;
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
xLogInitialize("Core_Graphics_Tests.txt");
|
||||
xLogActivateStory("testing");
|
||||
xLogActivateStory("debug");
|
||||
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
return result;
|
||||
}
|
||||
46
tjp/core/graphics/Color.hpp
Normal file
46
tjp/core/graphics/Color.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tjp/core/math/Vector3.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace tjp::core::graphics {
|
||||
|
||||
// https://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both
|
||||
template<typename T>
|
||||
T clamp(const T &t, T l=0, T r=1)
|
||||
{
|
||||
return std::min(std::max(t, l), r);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
math::Vector3<T> saturate(const math::Vector3<T> &v)
|
||||
{
|
||||
return { clamp(v[0]), clamp(v[1]), clamp(v[2]) };
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
math::Vector3<T> hue(T H)
|
||||
{
|
||||
T R = abs(H * 6 - 3) - 1;
|
||||
T G = 2 - abs(H * 6 - 2);
|
||||
T B = 2 - abs(H * 6 - 4);
|
||||
return saturate(math::Vector3<T> { R,G,B });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
math::Vector3<T> hsv2rgb(const math::Vector3<T> &hsv)
|
||||
{
|
||||
return ((hue(hsv[0]) - math::Vector3<T> { 1,1,1 }) * hsv[1] + math::Vector3<T> { 1,1,1 }) * hsv[2];
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
62
tjp/core/graphics/Colors.cpp
Normal file
62
tjp/core/graphics/Colors.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// Bridge.m
|
||||
// BgfxClient
|
||||
//
|
||||
// Created by Timothy Prepscius on 8/28/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Colors.hpp"
|
||||
|
||||
#include <tjp/core/math/Vector4.inl>
|
||||
#include <tjp/core/time/Time.hpp>
|
||||
|
||||
namespace tjp::core::graphics::colors {
|
||||
|
||||
Colors::Colors ()
|
||||
{
|
||||
}
|
||||
|
||||
Colors::Colors(std::initializer_list<IndexedColor> initializer)
|
||||
{
|
||||
colors.resize(initializer.size());
|
||||
|
||||
for (auto &[index, color]: initializer)
|
||||
set(index, color);
|
||||
}
|
||||
|
||||
Color Colors::get(ColorIndex index)
|
||||
{
|
||||
if (index < colors.size())
|
||||
return colors[index];
|
||||
|
||||
return Color { 1,0,1,1 };
|
||||
}
|
||||
|
||||
void Colors::set(int index, const Color &color)
|
||||
{
|
||||
if (colors.size() <= index)
|
||||
colors.resize(index+1);
|
||||
|
||||
colors[index] = color;
|
||||
}
|
||||
|
||||
|
||||
void ColorManager::transitionTo(const Colors &c, time::Duration duration)
|
||||
{
|
||||
c0 = c;
|
||||
}
|
||||
|
||||
Color ColorManager::get(ColorIndex index)
|
||||
{
|
||||
if (transition == 0)
|
||||
return c0.get(index);
|
||||
|
||||
return scale(
|
||||
transition,
|
||||
c0.get(index),
|
||||
c1.get(index)
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
25
tjp/core/graphics/Colors.h
Normal file
25
tjp/core/graphics/Colors.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Bridge.m
|
||||
// BgfxClient
|
||||
//
|
||||
// Created by Timothy Prepscius on 8/28/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tjp/core/containers/Vector.h>
|
||||
|
||||
#include <tjp/core/math/Vector4.h>
|
||||
|
||||
namespace tjp::core::graphics::colors {
|
||||
|
||||
using ColorIndex = int;
|
||||
using Color = math::Vector4f;
|
||||
using IndexedColor = std::pair<int, Color>;
|
||||
using IndexedColors = Vector<IndexedColor>;
|
||||
|
||||
struct Colors;
|
||||
struct ColorManager;
|
||||
|
||||
} // namespace
|
||||
64
tjp/core/graphics/Colors.hpp
Normal file
64
tjp/core/graphics/Colors.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Bridge.m
|
||||
// BgfxClient
|
||||
//
|
||||
// Created by Timothy Prepscius on 8/28/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Colors.h"
|
||||
|
||||
#include <tjp/core/containers/Vector.h>
|
||||
#include <tjp/core/math/Vector4.hpp>
|
||||
|
||||
#include <tjp/core/time/Time.h>
|
||||
|
||||
namespace tjp::core::graphics::colors {
|
||||
|
||||
template<typename T>
|
||||
T scale (float v, const T &l, const T &r)
|
||||
{
|
||||
return v * (r - l) + l;
|
||||
}
|
||||
|
||||
struct Colors
|
||||
{
|
||||
Vector<Color> colors;
|
||||
|
||||
Colors ();
|
||||
Colors(std::initializer_list<IndexedColor> initializer);
|
||||
|
||||
Color get(int index);
|
||||
void set(ColorIndex index, const Color &color);
|
||||
|
||||
template<typename T>
|
||||
Color get(T index)
|
||||
{
|
||||
return get((int)index);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void set(T index, Color color)
|
||||
{
|
||||
set((int)index, color);
|
||||
}
|
||||
} ;
|
||||
|
||||
struct ColorManager
|
||||
{
|
||||
Colors c0, c1;
|
||||
float transition = 0;
|
||||
|
||||
void transitionTo(const Colors &c, time::Duration duration);
|
||||
Color get(ColorIndex index);
|
||||
|
||||
template<typename T>
|
||||
Color get(T index)
|
||||
{
|
||||
return get((int)index);
|
||||
}
|
||||
} ;
|
||||
|
||||
} // namespace
|
||||
38
tjp/core/graphics/Geometry.h
Normal file
38
tjp/core/graphics/Geometry.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tjp/core/math/Vector3.hpp>
|
||||
#include <tjp/core/math/Vector2.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace tjp {
|
||||
namespace core {
|
||||
namespace graphics {
|
||||
|
||||
namespace geometry
|
||||
{
|
||||
|
||||
template<typename R, typename I=int>
|
||||
struct Geometry
|
||||
{
|
||||
std::vector<math::Vector3<R>> vertices;
|
||||
std::vector<I> indices;
|
||||
std::vector<math::Vector3<R>> normals;
|
||||
std::vector<math::Vector2<R>> uvs;
|
||||
} ;
|
||||
|
||||
template<typename Real, typename Index>
|
||||
Geometry<Real,Index> sphere(unsigned int numZSamples,
|
||||
unsigned int numRadialSamples, Real radius, bool outside);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
189
tjp/core/graphics/Geometry.hpp
Normal file
189
tjp/core/graphics/Geometry.hpp
Normal file
@@ -0,0 +1,189 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Geometry.h"
|
||||
#include <array>
|
||||
#include <tjp/core/assert/debug_assert.h>
|
||||
#include <tjp/core/math/Real.hpp>
|
||||
#include <tjp/core/math/Vector3.inl>
|
||||
|
||||
namespace tjp::core::graphics::geometry {
|
||||
|
||||
template<typename Index>
|
||||
void ReverseTriangleOrder(std::vector<Index> &indices)
|
||||
{
|
||||
auto numTriangles = indices.size()/3;
|
||||
for (unsigned int t = 0; t < numTriangles; ++t)
|
||||
{
|
||||
std::swap(indices[t*3 + 1], indices[t*3 + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename Real, typename Index>
|
||||
Geometry<Real, Index> sphere(unsigned int numZSamples,
|
||||
unsigned int numRadialSamples, Real radius, bool mOutside)
|
||||
{
|
||||
Geometry<Real, Index> result;
|
||||
using namespace math;
|
||||
|
||||
const Real _0 = 0;
|
||||
const Real _1 = 1;
|
||||
const Real _2 = 2;
|
||||
|
||||
// Quantities derived from inputs.
|
||||
unsigned int zsm1 = numZSamples - 1;
|
||||
unsigned int zsm2 = numZSamples - 2;
|
||||
unsigned int zsm3 = numZSamples - 3;
|
||||
unsigned int rsp1 = numRadialSamples + 1;
|
||||
Real invRS = _1 / static_cast<Real>(numRadialSamples);
|
||||
Real zFactor = _2 / static_cast<Real>(zsm1);
|
||||
unsigned int numVertices = zsm2 * rsp1 + 2;
|
||||
unsigned int numTriangles = 2 * zsm2 * numRadialSamples;
|
||||
|
||||
// Generate geometry.
|
||||
result.vertices.resize(numVertices);
|
||||
result.normals.resize(numVertices);
|
||||
result.uvs.resize(numVertices);
|
||||
|
||||
Vector3<Real> pos, nor;
|
||||
Vector2<Real> tcd;
|
||||
|
||||
// Generate points on the unit circle to be used in computing the mesh
|
||||
// points on a sphere slice.
|
||||
std::vector<Real> cs(rsp1), sn(rsp1);
|
||||
for (unsigned int r = 0; r < numRadialSamples; ++r)
|
||||
{
|
||||
Real angle = invRS * r * constants<Real>::TWO_PI;
|
||||
cs[r] = std::cos(angle);
|
||||
sn[r] = std::sin(angle);
|
||||
}
|
||||
cs[numRadialSamples] = cs[0];
|
||||
sn[numRadialSamples] = sn[0];
|
||||
|
||||
// Generate the sphere itself.
|
||||
unsigned int i = 0;
|
||||
for (unsigned int z = 1; z < zsm1; ++z)
|
||||
{
|
||||
Real zFraction = -_1 + zFactor*static_cast<Real>(z); // in (-1,1)
|
||||
Real zValue = radius*zFraction;
|
||||
|
||||
// Compute center of slice.
|
||||
Vector3<Real> sliceCenter{ _0, _0, zValue };
|
||||
|
||||
// Compute radius of slice.
|
||||
Real sliceRadius = std::sqrt(std::max(radius * radius - zValue * zValue, _0));
|
||||
|
||||
// Compute slice vertices with duplication at endpoint.
|
||||
for (unsigned int r = 0; r <= numRadialSamples; ++r, ++i)
|
||||
{
|
||||
float radialFraction = r * invRS; // in [0,1)
|
||||
Vector3<Real> radial{ cs[r], sn[r], _0 };
|
||||
pos = sliceCenter + sliceRadius * radial;
|
||||
nor = pos.normalize();
|
||||
if (!mOutside)
|
||||
{
|
||||
nor = -nor;
|
||||
}
|
||||
|
||||
tcd = { radialFraction, Real(0.5) * (zFraction + _1) };
|
||||
|
||||
result.vertices[i] = pos;
|
||||
result.normals[i] = nor;
|
||||
result.uvs[i] = tcd;
|
||||
}
|
||||
}
|
||||
|
||||
// The point at the south pole.
|
||||
pos = Vector3<Real> { _0, _0, -radius };
|
||||
if (mOutside)
|
||||
{
|
||||
nor = Vector3<Real> { _0, _0, -_1 };
|
||||
}
|
||||
else
|
||||
{
|
||||
nor = Vector3<Real> { _0, _0, _1 };
|
||||
}
|
||||
tcd = { Real(0.5), _0 };
|
||||
result.vertices[i] = pos;
|
||||
result.normals[i] = nor;
|
||||
result.uvs[i] = tcd;
|
||||
++i;
|
||||
|
||||
// The point at the north pole.
|
||||
pos = Vector3<Real> { _0, _0, radius };
|
||||
if (mOutside)
|
||||
{
|
||||
nor = Vector3<Real> { _0, _0, _1 };
|
||||
}
|
||||
else
|
||||
{
|
||||
nor = Vector3<Real> { _0, _0, -_1 };
|
||||
}
|
||||
tcd = { Real(0.5), Real(1.0) };
|
||||
result.vertices[i] = pos;
|
||||
result.normals[i] = nor;
|
||||
result.uvs[i] = tcd;
|
||||
++i;
|
||||
|
||||
debug_assert(i == numVertices);
|
||||
|
||||
// Generate indices (outside view).
|
||||
result.indices.resize(numTriangles*3);
|
||||
unsigned int t = 0;
|
||||
for (unsigned int z = 0, zStart = 0; z < zsm3; ++z)
|
||||
{
|
||||
unsigned int i0 = zStart;
|
||||
unsigned int i1 = i0 + 1;
|
||||
zStart += rsp1;
|
||||
unsigned int i2 = zStart;
|
||||
unsigned int i3 = i2 + 1;
|
||||
for (i = 0; i < numRadialSamples; ++i, ++i0, ++i1, ++i2, ++i3)
|
||||
{
|
||||
result.indices[t*3 + 0] = i0;
|
||||
result.indices[t*3 + 1] = i1;
|
||||
result.indices[t*3 + 2] = i2;
|
||||
++t;
|
||||
|
||||
result.indices[t*3 + 0] = i1;
|
||||
result.indices[t*3 + 1] = i3;
|
||||
result.indices[t*3 + 2] = i2;
|
||||
++t;
|
||||
}
|
||||
}
|
||||
|
||||
// The south pole triangles (outside view).
|
||||
unsigned int numVerticesM2 = numVertices - 2;
|
||||
for (i = 0; i < numRadialSamples; ++i, ++t)
|
||||
{
|
||||
result.indices[t*3 + 0] = i;
|
||||
result.indices[t*3 + 1] = numVerticesM2;
|
||||
result.indices[t*3 + 2] = i+1;
|
||||
}
|
||||
|
||||
// The north pole triangles (outside view).
|
||||
unsigned int numVerticesM1 = numVertices - 1, offset = zsm3 * rsp1;
|
||||
for (i = 0; i < numRadialSamples; ++i, ++t)
|
||||
{
|
||||
result.indices[t*3 + 0] = i + offset;
|
||||
result.indices[t*3 + 1] = i + 1 + offset;
|
||||
result.indices[t*3 + 2] = numVerticesM1;
|
||||
}
|
||||
|
||||
if (!mOutside)
|
||||
{
|
||||
ReverseTriangleOrder(result.indices);
|
||||
}
|
||||
|
||||
debug_assert(t == numTriangles);
|
||||
|
||||
// Create the mesh.
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
17
tjp/core/graphics/SDF.h
Normal file
17
tjp/core/graphics/SDF.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SDF_deadreckoning.h"
|
||||
|
||||
namespace tjp::core::graphics::sdf {
|
||||
|
||||
using namespace deadreckoning;
|
||||
|
||||
} // namespace
|
||||
259
tjp/core/graphics/SDF_deadreckoning.cpp
Normal file
259
tjp/core/graphics/SDF_deadreckoning.cpp
Normal file
@@ -0,0 +1,259 @@
|
||||
// "dead reckoning" transform function which generates signed distance field
|
||||
// from binary image.
|
||||
//
|
||||
// "The Dead Reckoning algorithm" is described in Fig.3 of the following paper:
|
||||
// The "dead reckoning" signed distance transform by George J. Grevera
|
||||
// http://perso.ensta-paristech.fr/~manzaner/Download/IAD/Grevera_04.pdf
|
||||
//
|
||||
// License:
|
||||
// Copyright (C) 2021, Takayuki Matsuoka.
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <tjp/core/assert/debug_assert.h>
|
||||
|
||||
namespace tjp::core::graphics::sdf::deadreckoning {
|
||||
|
||||
// width Width of the binary image in pixels.
|
||||
// height Height of the binary image in pixels.
|
||||
// getBinaryPixel A function which returns pixel of binary image. true:inside, false:outside.
|
||||
// setSignedDistance A function which sets signed distance to the signed distance image.
|
||||
// - Distance has sign, in pixels.
|
||||
// - Positive means inside of binary image. Negative means outside.
|
||||
// - Distance is not normalized. Therefore, -6.5f means "6.5 pixel, outside"
|
||||
// +1.2f means "1.2 pixels, inside". You can find example of "normalization"
|
||||
// of signed distance in proc().
|
||||
|
||||
template<typename F0, typename F1>
|
||||
void deadReckoning(
|
||||
int width
|
||||
, int height
|
||||
, F0 getBinaryPixel
|
||||
, F1 setSignedDistance
|
||||
|
||||
// , const std::function<bool(int x, int y)>& getBinaryPixel
|
||||
// , const std::function<void(int x, int y, float signedDistance)>& setSignedDistance
|
||||
|
||||
) {
|
||||
const auto contains = [&](int x, int y) -> bool {
|
||||
return x >= 0 && x < width && y >= 0 && y < height;
|
||||
};
|
||||
|
||||
// I - a 2D binary image
|
||||
const bool outside = false;
|
||||
const bool inside = true;
|
||||
const auto I = [&](int x, int y) -> bool { return getBinaryPixel(x, y) ? inside : outside; };
|
||||
|
||||
// d - a 2D grey image representing the distance image
|
||||
std::vector<float> ds(width * height);
|
||||
const float inf = static_cast<float>(256 * 256 * 256);
|
||||
const auto getd = [&](int x, int y) -> float {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
return ds[y*width + x];
|
||||
};
|
||||
const auto setd = [&](int x, int y, float v) {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
ds[y*width + x] = v;
|
||||
};
|
||||
const auto distance = [](int x, int y) -> float {
|
||||
return std::hypot(static_cast<float>(x), static_cast<float>(y));
|
||||
};
|
||||
|
||||
// p - for each pixel, the corresponding border point
|
||||
struct Point { int x, y; };
|
||||
std::vector<Point> ps(width * height);
|
||||
const Point outOfBounds = { -1, -1 };
|
||||
const auto getp = [&](int x, int y) -> Point {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
return ps[y*width + x];
|
||||
};
|
||||
const auto setp = [&](int x, int y, const Point& p) {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
ps[y*width + x] = p;
|
||||
};
|
||||
|
||||
// initialize d
|
||||
// initialize immediate interior & exterior elements
|
||||
for(int y = 0; y < height; ++y) {
|
||||
for(int x = 0; x < width; ++x) {
|
||||
const bool c = I(x, y);
|
||||
const bool w = contains(x-1, y) ? I(x-1, y) : outside;
|
||||
const bool e = contains(x+1, y) ? I(x+1, y) : outside;
|
||||
const bool n = contains(x, y-1) ? I(x, y-1) : outside;
|
||||
const bool s = contains(x, y+1) ? I(x, y+1) : outside;
|
||||
if((w != c) || (e != c) || (n != c) || (s != c)) {
|
||||
setd(x, y, 0);
|
||||
setp(x, y, { x, y });
|
||||
} else {
|
||||
setd(x, y, inf);
|
||||
setp(x, y, outOfBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Perform minimum distance choice for single pixel, single direction.
|
||||
enum class Dir {
|
||||
NW, N, NE, // NW=(x-1, y-1), N=(x, y-1), NE=(x+1, y-1)
|
||||
W, E, // W =(x-1, y), E =(x+1, y)
|
||||
SW, S, SE // SW=(x-1, y+1), S=(x, y+1), SE=(x+1, y+1)
|
||||
};
|
||||
const auto f = [&](int x, int y, Dir dir) {
|
||||
// d1 - distance between two adjacent pixels in either the x or y direction
|
||||
const float d1 = 1.0f;
|
||||
|
||||
// d2 - distance between two diagonally adjacent pixels (sqrt(2))
|
||||
const float d2 = d1 * 1.4142135623730950488f;
|
||||
|
||||
int dx, dy;
|
||||
float od;
|
||||
switch(dir) {
|
||||
default:
|
||||
case Dir::NW: dx = -1; dy = -1; od = d2; break; // first pass
|
||||
case Dir::N: dx = 0; dy = -1; od = d1; break; // first pass
|
||||
case Dir::NE: dx = 1; dy = -1; od = d2; break; // first pass
|
||||
case Dir::W: dx = -1; dy = 0; od = d1; break; // first pass
|
||||
case Dir::E: dx = 1; dy = 0; od = d1; break; // final pass
|
||||
case Dir::SW: dx = -1; dy = 1; od = d2; break; // final pass
|
||||
case Dir::S: dx = 0; dy = 1; od = d1; break; // final pass
|
||||
case Dir::SE: dx = 1; dy = 1; od = d2; break; // final pass
|
||||
}
|
||||
const bool b = contains(x+dx, y+dy);
|
||||
const float cd = b ? getd(x+dx, y+dy) : inf;
|
||||
if(cd + od < getd(x, y)) {
|
||||
const Point p = b ? getp(x+dx, y+dy) : outOfBounds;
|
||||
setp(x, y, p);
|
||||
const int xx = x - p.x;
|
||||
const int yy = y - p.y;
|
||||
const float nd = distance(xx, yy);
|
||||
setd(x, y, nd);
|
||||
}
|
||||
};
|
||||
|
||||
// perform the first pass
|
||||
for(int y = 0; y < height; ++y) { // top to bottom
|
||||
for(int x = 0; x < width; ++x) { // left to right
|
||||
static const Dir dirs[] = { Dir::NW, Dir::N, Dir::NE, Dir::W };
|
||||
for(const Dir dir : dirs) {
|
||||
f(x, y, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// perform the final pass
|
||||
for(int y = height-1; y >= 0; --y) { // bottom to top
|
||||
for(int x = width-1; x >= 0; --x) { // right to left
|
||||
static const Dir dirs[] = { Dir::E, Dir::SW, Dir::S, Dir::SE };
|
||||
for(const Dir dir : dirs) {
|
||||
f(x, y, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// indicate inside & outside
|
||||
for(int y = 0; y < height; ++y) {
|
||||
for(int x = 0; x < width; ++x) {
|
||||
float d = getd(x, y);
|
||||
if(I(x, y) == outside) {
|
||||
d = -d; // Negative distance means outside.
|
||||
}
|
||||
setSignedDistance(x, y, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deadReckoning_computeRGBA (
|
||||
int spread,
|
||||
unsigned int width, unsigned int height,
|
||||
unsigned char *image)
|
||||
{
|
||||
auto srcRgbaImage = image;
|
||||
auto outRgbaImage = image;
|
||||
uint8_t threshA = 250;
|
||||
|
||||
spread = 16;
|
||||
|
||||
{
|
||||
// Convert an RGBA pixel to binary.
|
||||
const auto getBinaryPixel = [&](int x, int y) -> bool {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
const int o = (y * width + x) * 4;
|
||||
const uint8_t a = srcRgbaImage[o + 3];
|
||||
return a > threshA;
|
||||
};
|
||||
|
||||
// Normalize signed distance to [0,255] and write it as a RGBA pixel.
|
||||
const auto setSignedDistance = [&](int x, int y, float signedDistance) {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
const float d = ((signedDistance / spread) + 1.0f) * 128.0f;
|
||||
|
||||
const auto c = static_cast<uint8_t>(std::clamp(d, 0.0f, 255.0f));
|
||||
const int o = (y * width + x) * 4;
|
||||
outRgbaImage[o + 3] = c; // A
|
||||
};
|
||||
|
||||
deadReckoning(width, height, getBinaryPixel, setSignedDistance);
|
||||
}
|
||||
}
|
||||
|
||||
void deadReckoning_computeA (
|
||||
int spread,
|
||||
unsigned int width, unsigned int height,
|
||||
unsigned char *image)
|
||||
{
|
||||
auto srcRgbaImage = image;
|
||||
auto outRgbaImage = image;
|
||||
uint8_t threshA = 250;
|
||||
|
||||
spread = 16;
|
||||
|
||||
{
|
||||
const auto getBinaryPixel = [&](int x, int y) -> bool {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
|
||||
const int o = (y * width + x);
|
||||
debug_assert(o < width * height);
|
||||
|
||||
const uint8_t a = srcRgbaImage[o];
|
||||
return a > threshA;
|
||||
};
|
||||
|
||||
// Normalize signed distance to [0,255] and write it as a RGBA pixel.
|
||||
const auto setSignedDistance = [&](int x, int y, float signedDistance) {
|
||||
debug_assert(x < width && y < height && x >= 0 && y >= 0);
|
||||
|
||||
const float d = ((signedDistance / spread) + 1.0f) * 128.0f;
|
||||
|
||||
const auto c = static_cast<uint8_t>(std::clamp(d, 0.0f, 255.0f));
|
||||
const int o = (y * width + x);
|
||||
|
||||
debug_assert(o < width * height);
|
||||
outRgbaImage[o] = c; // A
|
||||
};
|
||||
|
||||
deadReckoning(width, height, getBinaryPixel, setSignedDistance);
|
||||
}
|
||||
}
|
||||
|
||||
void computeRGBA(
|
||||
size_t width, size_t height,
|
||||
unsigned char *image,
|
||||
int spread
|
||||
)
|
||||
{
|
||||
deadReckoning_computeRGBA(spread, (unsigned int)width, (unsigned int)height, (unsigned char *)image);
|
||||
}
|
||||
|
||||
void computeA(
|
||||
size_t width, size_t height,
|
||||
unsigned char *image,
|
||||
int spread
|
||||
)
|
||||
{
|
||||
deadReckoning_computeA(spread, (unsigned int)width, (unsigned int)height, (unsigned char *)image);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
25
tjp/core/graphics/SDF_deadreckoning.h
Normal file
25
tjp/core/graphics/SDF_deadreckoning.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace tjp::core::graphics::sdf::deadreckoning {
|
||||
|
||||
void computeRGBA(
|
||||
size_t width, size_t height,
|
||||
unsigned char *image,
|
||||
int spread = 16
|
||||
);
|
||||
|
||||
void computeA(
|
||||
size_t width, size_t height,
|
||||
unsigned char *image,
|
||||
int spread = 16
|
||||
);
|
||||
|
||||
} // namespace
|
||||
16
tjp/core/graphics/STB+Image.h
Normal file
16
tjp/core/graphics/STB+Image.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stb/stb_image.h>
|
||||
#include <stb/stb_image_write.h>
|
||||
#include <stb/deprecated/stb_image_resize.h>
|
||||
|
||||
STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len);
|
||||
|
||||
10
tjp/core/graphics/STB+Image.inl
Normal file
10
tjp/core/graphics/STB+Image.inl
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "STB+Image.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb/stb_image_write.h>
|
||||
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include <stb/deprecated/stb_image_resize.h>
|
||||
12
tjp/core/graphics/STB+TrueType.h
Normal file
12
tjp/core/graphics/STB+TrueType.h
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stb/stb_truetype.h>
|
||||
|
||||
2
tjp/core/graphics/STB+TrueType.inl
Normal file
2
tjp/core/graphics/STB+TrueType.inl
Normal file
@@ -0,0 +1,2 @@
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <stb/stb_truetype.h>
|
||||
10
tjp/core/graphics/STB.cpp
Normal file
10
tjp/core/graphics/STB.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#include "STB+Image.inl"
|
||||
#include "STB+TrueType.inl"
|
||||
12
tjp/core/graphics/glm.h
Normal file
12
tjp/core/graphics/glm.h
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// vuku.h
|
||||
// Core
|
||||
//
|
||||
// Created by Timothy Prepscius on 9/8/20.
|
||||
// Copyright © 2020 Timothy Prepscius. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
125
tjp/core/graphics/imgui-old/imconfig.h
Normal file
125
tjp/core/graphics/imgui-old/imconfig.h
Normal file
@@ -0,0 +1,125 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
|
||||
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||
//-----------------------------------------------------------------------------
|
||||
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||
//-----------------------------------------------------------------------------
|
||||
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
//---- Define assertion handler. Defaults to calling assert().
|
||||
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||
|
||||
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||
//#define IMGUI_API __declspec( dllexport )
|
||||
//#define IMGUI_API __declspec( dllimport )
|
||||
|
||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
|
||||
|
||||
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||||
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
|
||||
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
|
||||
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).
|
||||
|
||||
//---- Don't implement some functions to reduce linkage requirements.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||||
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
|
||||
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||
|
||||
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||
//#define IMGUI_USE_WCHAR32
|
||||
|
||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled
|
||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||
|
||||
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
|
||||
//#define IMGUI_USE_STB_SPRINTF
|
||||
|
||||
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||||
//#define IMGUI_ENABLE_FREETYPE
|
||||
|
||||
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||
|
||||
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
/*
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
|
||||
operator MyVec2() const { return MyVec2(x,y); }
|
||||
|
||||
#define IM_VEC4_CLASS_EXTRA \
|
||||
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
|
||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||
*/
|
||||
|
||||
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||
//#define ImDrawIdx unsigned int
|
||||
|
||||
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||
//struct ImDrawList;
|
||||
//struct ImDrawCmd;
|
||||
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||
//#define ImDrawCallback MyImDrawCallback
|
||||
|
||||
//---- Debug Tools: Macro to break in Debugger
|
||||
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||
//#define IM_DEBUG_BREAK __debugbreak()
|
||||
|
||||
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
|
||||
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
|
||||
// This adds a small runtime cost which is why it is not enabled by default.
|
||||
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
|
||||
|
||||
//---- Debug Tools: Enable slower asserts
|
||||
//#define IMGUI_DEBUG_PARANOID
|
||||
|
||||
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||
/*
|
||||
namespace ImGui
|
||||
{
|
||||
void MyFunction(const char* name, const MyMatrix44& v);
|
||||
}
|
||||
*/
|
||||
13547
tjp/core/graphics/imgui-old/imgui.cpp
Normal file
13547
tjp/core/graphics/imgui-old/imgui.cpp
Normal file
File diff suppressed because it is too large
Load Diff
3051
tjp/core/graphics/imgui-old/imgui.h
Normal file
3051
tjp/core/graphics/imgui-old/imgui.h
Normal file
File diff suppressed because it is too large
Load Diff
4162
tjp/core/graphics/imgui-old/imgui_draw.cpp
Normal file
4162
tjp/core/graphics/imgui-old/imgui_draw.cpp
Normal file
File diff suppressed because it is too large
Load Diff
662
tjp/core/graphics/imgui-old/imgui_impl_glfw.cpp
Normal file
662
tjp/core/graphics/imgui-old/imgui_impl_glfw.cpp
Normal file
@@ -0,0 +1,662 @@
|
||||
// dear imgui: Platform Backend for GLFW
|
||||
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
||||
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||
// (Requires: GLFW 3.1+)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
||||
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 2022-04-30: Inputs: Fixed ImGui_ImplGlfw_TranslateUntranslatedKey() for lower case letters on OSX.
|
||||
// 2022-03-23: Inputs: Fixed a regression in 1.87 which resulted in keyboard modifiers events being reported incorrectly on Linux/X11.
|
||||
// 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after initializing backend.
|
||||
// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
|
||||
// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
|
||||
// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
|
||||
// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
|
||||
// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
|
||||
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
|
||||
// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
|
||||
// 2021-08-17: *BREAKING CHANGE*: Now using glfwSetWindowFocusCallback() to calling io.AddFocusEvent(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() and forward it to the backend via ImGui_ImplGlfw_WindowFocusCallback().
|
||||
// 2021-07-29: *BREAKING CHANGE*: Now using glfwSetCursorEnterCallback(). MousePos is correctly reported when the host platform window is hovered but not focused. If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() callback and forward it to the backend via ImGui_ImplGlfw_CursorEnterCallback().
|
||||
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
||||
// 2020-01-17: Inputs: Disable error callback while assigning mouse cursors because some X11 setup don't have them and it generates errors.
|
||||
// 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor).
|
||||
// 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown.
|
||||
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
|
||||
// 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter().
|
||||
// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
|
||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
||||
// 2018-11-07: Inputs: When installing our GLFW callbacks, we save user's previously installed ones - if any - and chain call them.
|
||||
// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
|
||||
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
|
||||
// 2018-06-08: Misc: Extracted imgui_impl_glfw.cpp/.h away from the old combined GLFW+OpenGL/Vulkan examples.
|
||||
// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
|
||||
// 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value, passed to glfwSetCursor()).
|
||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
||||
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
|
||||
// 2018-01-25: Inputs: Added gamepad support if ImGuiConfigFlags_NavEnableGamepad is set.
|
||||
// 2018-01-25: Inputs: Honoring the io.WantSetMousePos by repositioning the mouse (when using navigation and ImGuiConfigFlags_NavMoveMouse is set).
|
||||
// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
|
||||
// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
|
||||
// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
|
||||
// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
|
||||
// Clang warnings with -Weverything
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
|
||||
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
|
||||
#if __has_warning("-Wzero-as-null-pointer-constant")
|
||||
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// GLFW
|
||||
#include <GLFW/glfw3.h>
|
||||
#ifdef _WIN32
|
||||
#undef APIENTRY
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3native.h> // for glfwGetWin32Window
|
||||
#endif
|
||||
#ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released?
|
||||
#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR
|
||||
#else
|
||||
#define GLFW_HAS_NEW_CURSORS (0)
|
||||
#endif
|
||||
#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetGamepadState() new api
|
||||
#define GLFW_HAS_GET_KEY_NAME (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwGetKeyName()
|
||||
|
||||
// GLFW data
|
||||
enum GlfwClientApi
|
||||
{
|
||||
GlfwClientApi_Unknown,
|
||||
GlfwClientApi_OpenGL,
|
||||
GlfwClientApi_Vulkan
|
||||
};
|
||||
|
||||
struct ImGui_ImplGlfw_Data
|
||||
{
|
||||
GLFWwindow* Window;
|
||||
GlfwClientApi ClientApi;
|
||||
double Time;
|
||||
GLFWwindow* MouseWindow;
|
||||
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||||
ImVec2 LastValidMousePos;
|
||||
bool InstalledCallbacks;
|
||||
|
||||
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
||||
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
|
||||
GLFWcursorposfun PrevUserCallbackCursorPos;
|
||||
GLFWcursorenterfun PrevUserCallbackCursorEnter;
|
||||
GLFWmousebuttonfun PrevUserCallbackMousebutton;
|
||||
GLFWscrollfun PrevUserCallbackScroll;
|
||||
GLFWkeyfun PrevUserCallbackKey;
|
||||
GLFWcharfun PrevUserCallbackChar;
|
||||
GLFWmonitorfun PrevUserCallbackMonitor;
|
||||
|
||||
ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
||||
// - Because glfwPollEvents() process all windows and some events may be called outside of it, you will need to register your own callbacks
|
||||
// (passing install_callbacks=false in ImGui_ImplGlfw_InitXXX functions), set the current dear imgui context and then call our callbacks.
|
||||
// - Otherwise we may need to store a GLFWWindow* -> ImGuiContext* map and handle this in the backend, adding a little bit of extra complexity to it.
|
||||
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
||||
static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData()
|
||||
{
|
||||
return ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData : NULL;
|
||||
}
|
||||
|
||||
// Functions
|
||||
static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data)
|
||||
{
|
||||
return glfwGetClipboardString((GLFWwindow*)user_data);
|
||||
}
|
||||
|
||||
static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text)
|
||||
{
|
||||
glfwSetClipboardString((GLFWwindow*)user_data, text);
|
||||
}
|
||||
|
||||
static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case GLFW_KEY_TAB: return ImGuiKey_Tab;
|
||||
case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow;
|
||||
case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow;
|
||||
case GLFW_KEY_UP: return ImGuiKey_UpArrow;
|
||||
case GLFW_KEY_DOWN: return ImGuiKey_DownArrow;
|
||||
case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp;
|
||||
case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
|
||||
case GLFW_KEY_HOME: return ImGuiKey_Home;
|
||||
case GLFW_KEY_END: return ImGuiKey_End;
|
||||
case GLFW_KEY_INSERT: return ImGuiKey_Insert;
|
||||
case GLFW_KEY_DELETE: return ImGuiKey_Delete;
|
||||
case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace;
|
||||
case GLFW_KEY_SPACE: return ImGuiKey_Space;
|
||||
case GLFW_KEY_ENTER: return ImGuiKey_Enter;
|
||||
case GLFW_KEY_ESCAPE: return ImGuiKey_Escape;
|
||||
case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||
case GLFW_KEY_COMMA: return ImGuiKey_Comma;
|
||||
case GLFW_KEY_MINUS: return ImGuiKey_Minus;
|
||||
case GLFW_KEY_PERIOD: return ImGuiKey_Period;
|
||||
case GLFW_KEY_SLASH: return ImGuiKey_Slash;
|
||||
case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon;
|
||||
case GLFW_KEY_EQUAL: return ImGuiKey_Equal;
|
||||
case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket;
|
||||
case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash;
|
||||
case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket;
|
||||
case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent;
|
||||
case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock;
|
||||
case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock;
|
||||
case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock;
|
||||
case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen;
|
||||
case GLFW_KEY_PAUSE: return ImGuiKey_Pause;
|
||||
case GLFW_KEY_KP_0: return ImGuiKey_Keypad0;
|
||||
case GLFW_KEY_KP_1: return ImGuiKey_Keypad1;
|
||||
case GLFW_KEY_KP_2: return ImGuiKey_Keypad2;
|
||||
case GLFW_KEY_KP_3: return ImGuiKey_Keypad3;
|
||||
case GLFW_KEY_KP_4: return ImGuiKey_Keypad4;
|
||||
case GLFW_KEY_KP_5: return ImGuiKey_Keypad5;
|
||||
case GLFW_KEY_KP_6: return ImGuiKey_Keypad6;
|
||||
case GLFW_KEY_KP_7: return ImGuiKey_Keypad7;
|
||||
case GLFW_KEY_KP_8: return ImGuiKey_Keypad8;
|
||||
case GLFW_KEY_KP_9: return ImGuiKey_Keypad9;
|
||||
case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal;
|
||||
case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
||||
case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
||||
case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract;
|
||||
case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd;
|
||||
case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter;
|
||||
case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual;
|
||||
case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
|
||||
case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
|
||||
case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
|
||||
case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper;
|
||||
case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
|
||||
case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl;
|
||||
case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt;
|
||||
case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper;
|
||||
case GLFW_KEY_MENU: return ImGuiKey_Menu;
|
||||
case GLFW_KEY_0: return ImGuiKey_0;
|
||||
case GLFW_KEY_1: return ImGuiKey_1;
|
||||
case GLFW_KEY_2: return ImGuiKey_2;
|
||||
case GLFW_KEY_3: return ImGuiKey_3;
|
||||
case GLFW_KEY_4: return ImGuiKey_4;
|
||||
case GLFW_KEY_5: return ImGuiKey_5;
|
||||
case GLFW_KEY_6: return ImGuiKey_6;
|
||||
case GLFW_KEY_7: return ImGuiKey_7;
|
||||
case GLFW_KEY_8: return ImGuiKey_8;
|
||||
case GLFW_KEY_9: return ImGuiKey_9;
|
||||
case GLFW_KEY_A: return ImGuiKey_A;
|
||||
case GLFW_KEY_B: return ImGuiKey_B;
|
||||
case GLFW_KEY_C: return ImGuiKey_C;
|
||||
case GLFW_KEY_D: return ImGuiKey_D;
|
||||
case GLFW_KEY_E: return ImGuiKey_E;
|
||||
case GLFW_KEY_F: return ImGuiKey_F;
|
||||
case GLFW_KEY_G: return ImGuiKey_G;
|
||||
case GLFW_KEY_H: return ImGuiKey_H;
|
||||
case GLFW_KEY_I: return ImGuiKey_I;
|
||||
case GLFW_KEY_J: return ImGuiKey_J;
|
||||
case GLFW_KEY_K: return ImGuiKey_K;
|
||||
case GLFW_KEY_L: return ImGuiKey_L;
|
||||
case GLFW_KEY_M: return ImGuiKey_M;
|
||||
case GLFW_KEY_N: return ImGuiKey_N;
|
||||
case GLFW_KEY_O: return ImGuiKey_O;
|
||||
case GLFW_KEY_P: return ImGuiKey_P;
|
||||
case GLFW_KEY_Q: return ImGuiKey_Q;
|
||||
case GLFW_KEY_R: return ImGuiKey_R;
|
||||
case GLFW_KEY_S: return ImGuiKey_S;
|
||||
case GLFW_KEY_T: return ImGuiKey_T;
|
||||
case GLFW_KEY_U: return ImGuiKey_U;
|
||||
case GLFW_KEY_V: return ImGuiKey_V;
|
||||
case GLFW_KEY_W: return ImGuiKey_W;
|
||||
case GLFW_KEY_X: return ImGuiKey_X;
|
||||
case GLFW_KEY_Y: return ImGuiKey_Y;
|
||||
case GLFW_KEY_Z: return ImGuiKey_Z;
|
||||
case GLFW_KEY_F1: return ImGuiKey_F1;
|
||||
case GLFW_KEY_F2: return ImGuiKey_F2;
|
||||
case GLFW_KEY_F3: return ImGuiKey_F3;
|
||||
case GLFW_KEY_F4: return ImGuiKey_F4;
|
||||
case GLFW_KEY_F5: return ImGuiKey_F5;
|
||||
case GLFW_KEY_F6: return ImGuiKey_F6;
|
||||
case GLFW_KEY_F7: return ImGuiKey_F7;
|
||||
case GLFW_KEY_F8: return ImGuiKey_F8;
|
||||
case GLFW_KEY_F9: return ImGuiKey_F9;
|
||||
case GLFW_KEY_F10: return ImGuiKey_F10;
|
||||
case GLFW_KEY_F11: return ImGuiKey_F11;
|
||||
case GLFW_KEY_F12: return ImGuiKey_F12;
|
||||
default: return ImGuiKey_None;
|
||||
}
|
||||
}
|
||||
|
||||
static int ImGui_ImplGlfw_KeyToModifier(int key)
|
||||
{
|
||||
if (key == GLFW_KEY_LEFT_CONTROL || key == GLFW_KEY_RIGHT_CONTROL)
|
||||
return GLFW_MOD_CONTROL;
|
||||
if (key == GLFW_KEY_LEFT_SHIFT || key == GLFW_KEY_RIGHT_SHIFT)
|
||||
return GLFW_MOD_SHIFT;
|
||||
if (key == GLFW_KEY_LEFT_ALT || key == GLFW_KEY_RIGHT_ALT)
|
||||
return GLFW_MOD_ALT;
|
||||
if (key == GLFW_KEY_LEFT_SUPER || key == GLFW_KEY_RIGHT_SUPER)
|
||||
return GLFW_MOD_SUPER;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ImGui_ImplGlfw_UpdateKeyModifiers(int mods)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddKeyEvent(ImGuiKey_ModCtrl, (mods & GLFW_MOD_CONTROL) != 0);
|
||||
io.AddKeyEvent(ImGuiKey_ModShift, (mods & GLFW_MOD_SHIFT) != 0);
|
||||
io.AddKeyEvent(ImGuiKey_ModAlt, (mods & GLFW_MOD_ALT) != 0);
|
||||
io.AddKeyEvent(ImGuiKey_ModSuper, (mods & GLFW_MOD_SUPER) != 0);
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if (bd->PrevUserCallbackMousebutton != NULL && window == bd->Window)
|
||||
bd->PrevUserCallbackMousebutton(window, button, action, mods);
|
||||
|
||||
ImGui_ImplGlfw_UpdateKeyModifiers(mods);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (button >= 0 && button < ImGuiMouseButton_COUNT)
|
||||
io.AddMouseButtonEvent(button, action == GLFW_PRESS);
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if (bd->PrevUserCallbackScroll != NULL && window == bd->Window)
|
||||
bd->PrevUserCallbackScroll(window, xoffset, yoffset);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
|
||||
}
|
||||
|
||||
static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
|
||||
{
|
||||
#if GLFW_HAS_GET_KEY_NAME && !defined(__EMSCRIPTEN__)
|
||||
// GLFW 3.1+ attempts to "untranslate" keys, which goes the opposite of what every other framework does, making using lettered shortcuts difficult.
|
||||
// (It had reasons to do so: namely GLFW is/was more likely to be used for WASD-type game controls rather than lettered shortcuts, but IHMO the 3.1 change could have been done differently)
|
||||
// See https://github.com/glfw/glfw/issues/1502 for details.
|
||||
// Adding a workaround to undo this (so our keys are translated->untranslated->translated, likely a lossy process).
|
||||
// This won't cover edge cases but this is at least going to cover common cases.
|
||||
if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL)
|
||||
return key;
|
||||
const char* key_name = glfwGetKeyName(key, scancode);
|
||||
if (key_name && key_name[0] != 0 && key_name[1] == 0)
|
||||
{
|
||||
const char char_names[] = "`-=[]\\,;\'./";
|
||||
const int char_keys[] = { GLFW_KEY_GRAVE_ACCENT, GLFW_KEY_MINUS, GLFW_KEY_EQUAL, GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_BACKSLASH, GLFW_KEY_COMMA, GLFW_KEY_SEMICOLON, GLFW_KEY_APOSTROPHE, GLFW_KEY_PERIOD, GLFW_KEY_SLASH, 0 };
|
||||
IM_ASSERT(IM_ARRAYSIZE(char_names) == IM_ARRAYSIZE(char_keys));
|
||||
if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); }
|
||||
else if (key_name[0] >= 'A' && key_name[0] <= 'Z') { key = GLFW_KEY_A + (key_name[0] - 'A'); }
|
||||
else if (key_name[0] >= 'a' && key_name[0] <= 'z') { key = GLFW_KEY_A + (key_name[0] - 'a'); }
|
||||
else if (const char* p = strchr(char_names, key_name[0])) { key = char_keys[p - char_names]; }
|
||||
}
|
||||
// if (action == GLFW_PRESS) printf("key %d scancode %d name '%s'\n", key, scancode, key_name);
|
||||
#else
|
||||
IM_UNUSED(scancode);
|
||||
#endif
|
||||
return key;
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if (bd->PrevUserCallbackKey != NULL && window == bd->Window)
|
||||
bd->PrevUserCallbackKey(window, keycode, scancode, action, mods);
|
||||
|
||||
if (action != GLFW_PRESS && action != GLFW_RELEASE)
|
||||
return;
|
||||
|
||||
// Workaround: X11 does not include current pressed/released modifier key in 'mods' flags. https://github.com/glfw/glfw/issues/1630
|
||||
if (int keycode_to_mod = ImGui_ImplGlfw_KeyToModifier(keycode))
|
||||
mods = (action == GLFW_PRESS) ? (mods | keycode_to_mod) : (mods & ~keycode_to_mod);
|
||||
ImGui_ImplGlfw_UpdateKeyModifiers(mods);
|
||||
|
||||
keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuiKey imgui_key = ImGui_ImplGlfw_KeyToImGuiKey(keycode);
|
||||
io.AddKeyEvent(imgui_key, (action == GLFW_PRESS));
|
||||
io.SetKeyEventNativeData(imgui_key, keycode, scancode); // To support legacy indexing (<1.87 user code)
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if (bd->PrevUserCallbackWindowFocus != NULL && window == bd->Window)
|
||||
bd->PrevUserCallbackWindowFocus(window, focused);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddFocusEvent(focused != 0);
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if (bd->PrevUserCallbackCursorPos != NULL && window == bd->Window)
|
||||
bd->PrevUserCallbackCursorPos(window, x, y);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddMousePosEvent((float)x, (float)y);
|
||||
bd->LastValidMousePos = ImVec2((float)x, (float)y);
|
||||
}
|
||||
|
||||
// Workaround: X11 seems to send spurious Leave/Enter events which would make us lose our position,
|
||||
// so we back it up and restore on Leave/Enter (see https://github.com/ocornut/imgui/issues/4984)
|
||||
void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if (bd->PrevUserCallbackCursorEnter != NULL && window == bd->Window)
|
||||
bd->PrevUserCallbackCursorEnter(window, entered);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (entered)
|
||||
{
|
||||
bd->MouseWindow = window;
|
||||
io.AddMousePosEvent(bd->LastValidMousePos.x, bd->LastValidMousePos.y);
|
||||
}
|
||||
else if (!entered && bd->MouseWindow == window)
|
||||
{
|
||||
bd->LastValidMousePos = io.MousePos;
|
||||
bd->MouseWindow = NULL;
|
||||
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if (bd->PrevUserCallbackChar != NULL && window == bd->Window)
|
||||
bd->PrevUserCallbackChar(window, c);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddInputCharacter(c);
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int)
|
||||
{
|
||||
// Unused in 'master' branch but 'docking' branch will use this, so we declare it ahead of it so if you have to install callbacks you can install this one too.
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
IM_ASSERT(bd->InstalledCallbacks == false && "Callbacks already installed!");
|
||||
IM_ASSERT(bd->Window == window);
|
||||
|
||||
bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback);
|
||||
bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback);
|
||||
bd->PrevUserCallbackCursorPos = glfwSetCursorPosCallback(window, ImGui_ImplGlfw_CursorPosCallback);
|
||||
bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
|
||||
bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
|
||||
bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
|
||||
bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
|
||||
bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback);
|
||||
bd->InstalledCallbacks = true;
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window)
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
IM_ASSERT(bd->InstalledCallbacks == true && "Callbacks not installed!");
|
||||
IM_ASSERT(bd->Window == window);
|
||||
|
||||
glfwSetWindowFocusCallback(window, bd->PrevUserCallbackWindowFocus);
|
||||
glfwSetCursorEnterCallback(window, bd->PrevUserCallbackCursorEnter);
|
||||
glfwSetCursorPosCallback(window, bd->PrevUserCallbackCursorPos);
|
||||
glfwSetMouseButtonCallback(window, bd->PrevUserCallbackMousebutton);
|
||||
glfwSetScrollCallback(window, bd->PrevUserCallbackScroll);
|
||||
glfwSetKeyCallback(window, bd->PrevUserCallbackKey);
|
||||
glfwSetCharCallback(window, bd->PrevUserCallbackChar);
|
||||
glfwSetMonitorCallback(bd->PrevUserCallbackMonitor);
|
||||
bd->InstalledCallbacks = false;
|
||||
bd->PrevUserCallbackWindowFocus = NULL;
|
||||
bd->PrevUserCallbackCursorEnter = NULL;
|
||||
bd->PrevUserCallbackCursorPos = NULL;
|
||||
bd->PrevUserCallbackMousebutton = NULL;
|
||||
bd->PrevUserCallbackScroll = NULL;
|
||||
bd->PrevUserCallbackKey = NULL;
|
||||
bd->PrevUserCallbackChar = NULL;
|
||||
bd->PrevUserCallbackMonitor = NULL;
|
||||
}
|
||||
|
||||
static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!");
|
||||
|
||||
// Setup backend capabilities flags
|
||||
ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
|
||||
io.BackendPlatformUserData = (void*)bd;
|
||||
io.BackendPlatformName = "imgui_impl_glfw";
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||
|
||||
bd->Window = window;
|
||||
bd->Time = 0.0;
|
||||
|
||||
io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
||||
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
||||
io.ClipboardUserData = bd->Window;
|
||||
|
||||
// Set platform dependent data in viewport
|
||||
#if defined(_WIN32)
|
||||
ImGui::GetMainViewport()->PlatformHandleRaw = (void*)glfwGetWin32Window(bd->Window);
|
||||
#endif
|
||||
|
||||
// Create mouse cursors
|
||||
// (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
|
||||
// GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
|
||||
// Missing cursors will return NULL and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
|
||||
GLFWerrorfun prev_error_callback = glfwSetErrorCallback(NULL);
|
||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
|
||||
#if GLFW_HAS_NEW_CURSORS
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR);
|
||||
#else
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||
#endif
|
||||
glfwSetErrorCallback(prev_error_callback);
|
||||
|
||||
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
||||
if (install_callbacks)
|
||||
ImGui_ImplGlfw_InstallCallbacks(window);
|
||||
|
||||
bd->ClientApi = client_api;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks)
|
||||
{
|
||||
return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_OpenGL);
|
||||
}
|
||||
|
||||
bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks)
|
||||
{
|
||||
return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Vulkan);
|
||||
}
|
||||
|
||||
bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks)
|
||||
{
|
||||
return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Unknown);
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_Shutdown()
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
IM_ASSERT(bd != NULL && "No platform backend to shutdown, or already shutdown?");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (bd->InstalledCallbacks)
|
||||
ImGui_ImplGlfw_RestoreCallbacks(bd->Window);
|
||||
|
||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||
glfwDestroyCursor(bd->MouseCursors[cursor_n]);
|
||||
|
||||
io.BackendPlatformName = NULL;
|
||||
io.BackendPlatformUserData = NULL;
|
||||
IM_DELETE(bd);
|
||||
}
|
||||
|
||||
static void ImGui_ImplGlfw_UpdateMouseData()
|
||||
{
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
const bool is_app_focused = true;
|
||||
#else
|
||||
const bool is_app_focused = glfwGetWindowAttrib(bd->Window, GLFW_FOCUSED) != 0;
|
||||
#endif
|
||||
if (is_app_focused)
|
||||
{
|
||||
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
||||
if (io.WantSetMousePos)
|
||||
glfwSetCursorPos(bd->Window, (double)io.MousePos.x, (double)io.MousePos.y);
|
||||
|
||||
// (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured)
|
||||
if (is_app_focused && bd->MouseWindow == NULL)
|
||||
{
|
||||
double mouse_x, mouse_y;
|
||||
glfwGetCursorPos(bd->Window, &mouse_x, &mouse_y);
|
||||
io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
|
||||
bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGui_ImplGlfw_UpdateMouseCursor()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||
return;
|
||||
|
||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
||||
{
|
||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||
glfwSetInputMode(bd->Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show OS mouse cursor
|
||||
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
|
||||
glfwSetCursor(bd->Window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
|
||||
glfwSetInputMode(bd->Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
// Update gamepad inputs
|
||||
static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
|
||||
static void ImGui_ImplGlfw_UpdateGamepads()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
||||
return;
|
||||
|
||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||
#if GLFW_HAS_GAMEPAD_API
|
||||
GLFWgamepadstate gamepad;
|
||||
if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad))
|
||||
return;
|
||||
#define MAP_BUTTON(KEY_NO, BUTTON_NO, _UNUSED) do { io.AddKeyEvent(KEY_NO, gamepad.buttons[BUTTON_NO] != 0); } while (0)
|
||||
#define MAP_ANALOG(KEY_NO, AXIS_NO, _UNUSED, V0, V1) do { float v = gamepad.axes[AXIS_NO]; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
|
||||
#else
|
||||
int axes_count = 0, buttons_count = 0;
|
||||
const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
|
||||
const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
|
||||
if (axes_count == 0 || buttons_count == 0)
|
||||
return;
|
||||
#define MAP_BUTTON(KEY_NO, _UNUSED, BUTTON_NO) do { io.AddKeyEvent(KEY_NO, (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS)); } while (0)
|
||||
#define MAP_ANALOG(KEY_NO, _UNUSED, AXIS_NO, V0, V1) do { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
|
||||
#endif
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
MAP_BUTTON(ImGuiKey_GamepadStart, GLFW_GAMEPAD_BUTTON_START, 7);
|
||||
MAP_BUTTON(ImGuiKey_GamepadBack, GLFW_GAMEPAD_BUTTON_BACK, 6);
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, GLFW_GAMEPAD_BUTTON_X, 2); // Xbox X, PS Square
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceUp, GLFW_GAMEPAD_BUTTON_Y, 3); // Xbox Y, PS Triangle
|
||||
MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, GLFW_GAMEPAD_BUTTON_DPAD_LEFT, 13);
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadRight, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, 11);
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadUp, GLFW_GAMEPAD_BUTTON_DPAD_UP, 10);
|
||||
MAP_BUTTON(ImGuiKey_GamepadDpadDown, GLFW_GAMEPAD_BUTTON_DPAD_DOWN, 12);
|
||||
MAP_BUTTON(ImGuiKey_GamepadL1, GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, 4);
|
||||
MAP_BUTTON(ImGuiKey_GamepadR1, GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, 5);
|
||||
MAP_ANALOG(ImGuiKey_GamepadL2, GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, 4, -0.75f, +1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadR2, GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, 5, -0.75f, +1.0f);
|
||||
MAP_BUTTON(ImGuiKey_GamepadL3, GLFW_GAMEPAD_BUTTON_LEFT_THUMB, 8);
|
||||
MAP_BUTTON(ImGuiKey_GamepadR3, GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, 9);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, GLFW_GAMEPAD_AXIS_LEFT_X, 0, -0.25f, -1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickRight, GLFW_GAMEPAD_AXIS_LEFT_X, 0, +0.25f, +1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickUp, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, -0.25f, -1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadLStickDown, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, +0.25f, +1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, -0.25f, -1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadRStickRight, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, +0.25f, +1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadRStickUp, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, -0.25f, -1.0f);
|
||||
MAP_ANALOG(ImGuiKey_GamepadRStickDown, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, +0.25f, +1.0f);
|
||||
#undef MAP_BUTTON
|
||||
#undef MAP_ANALOG
|
||||
}
|
||||
|
||||
void ImGui_ImplGlfw_NewFrame()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||
IM_ASSERT(bd != NULL && "Did you call ImGui_ImplGlfw_InitForXXX()?");
|
||||
|
||||
// Setup display size (every frame to accommodate for window resizing)
|
||||
int w, h;
|
||||
int display_w, display_h;
|
||||
glfwGetWindowSize(bd->Window, &w, &h);
|
||||
glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
|
||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||
if (w > 0 && h > 0)
|
||||
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);
|
||||
|
||||
// Setup time step
|
||||
double current_time = glfwGetTime();
|
||||
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
|
||||
bd->Time = current_time;
|
||||
|
||||
ImGui_ImplGlfw_UpdateMouseData();
|
||||
ImGui_ImplGlfw_UpdateMouseCursor();
|
||||
|
||||
// Update game controllers (if enabled and available)
|
||||
ImGui_ImplGlfw_UpdateGamepads();
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
46
tjp/core/graphics/imgui-old/imgui_impl_glfw.h
Normal file
46
tjp/core/graphics/imgui-old/imgui_impl_glfw.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// dear imgui: Platform Backend for GLFW
|
||||
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
||||
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
|
||||
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||
|
||||
// About GLSL version:
|
||||
// The 'glsl_version' initialization parameter defaults to "#version 150" if NULL.
|
||||
// Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure!
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
|
||||
struct GLFWwindow;
|
||||
struct GLFWmonitor;
|
||||
|
||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks);
|
||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
|
||||
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
|
||||
|
||||
// GLFW callbacks (installer)
|
||||
// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
|
||||
// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks.
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
|
||||
|
||||
// GLFW callbacks (individual callbacks to call if you didn't install callbacks)
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
|
||||
IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event);
|
||||
1537
tjp/core/graphics/imgui-old/imgui_impl_vulkan.cpp
Normal file
1537
tjp/core/graphics/imgui-old/imgui_impl_vulkan.cpp
Normal file
File diff suppressed because it is too large
Load Diff
155
tjp/core/graphics/imgui-old/imgui_impl_vulkan.h
Normal file
155
tjp/core/graphics/imgui-old/imgui_impl_vulkan.h
Normal file
@@ -0,0 +1,155 @@
|
||||
// dear imgui: Renderer Backend for Vulkan
|
||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
|
||||
// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions.
|
||||
|
||||
// Important: on 32-bit systems, user texture binding is only supported if your imconfig file has '#define ImTextureID ImU64'.
|
||||
// See imgui_impl_vulkan.cpp file for details.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||
|
||||
// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
|
||||
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
||||
|
||||
// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
|
||||
// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
|
||||
// You will use those if you want to use this rendering backend in your engine/app.
|
||||
// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
|
||||
// the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
|
||||
// Read comments in imgui_impl_vulkan.h.
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
|
||||
// [Configuration] in order to use a custom Vulkan function loader:
|
||||
// (1) You'll need to disable default Vulkan function prototypes.
|
||||
// We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag.
|
||||
// In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit:
|
||||
// - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file
|
||||
// - Or as a compilation flag in your build system
|
||||
// - Or uncomment here (not recommended because you'd be modifying imgui sources!)
|
||||
// - Do not simply add it in a .cpp file!
|
||||
// (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function.
|
||||
// If you have no idea what this is, leave it alone!
|
||||
//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
||||
|
||||
// Vulkan includes
|
||||
#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
|
||||
#define VK_NO_PROTOTYPES
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
// Initialization data, for ImGui_ImplVulkan_Init()
|
||||
// [Please zero-clear before use!]
|
||||
struct ImGui_ImplVulkan_InitInfo
|
||||
{
|
||||
VkInstance Instance;
|
||||
VkPhysicalDevice PhysicalDevice;
|
||||
VkDevice Device;
|
||||
uint32_t QueueFamily;
|
||||
VkQueue Queue;
|
||||
VkPipelineCache PipelineCache;
|
||||
VkDescriptorPool DescriptorPool;
|
||||
uint32_t Subpass;
|
||||
uint32_t MinImageCount; // >= 2
|
||||
uint32_t ImageCount; // >= MinImageCount
|
||||
VkSampleCountFlagBits MSAASamples; // >= VK_SAMPLE_COUNT_1_BIT (0 -> default to VK_SAMPLE_COUNT_1_BIT)
|
||||
const VkAllocationCallbacks* Allocator;
|
||||
void (*CheckVkResultFn)(VkResult err);
|
||||
};
|
||||
|
||||
// Called by user code
|
||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass);
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE);
|
||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer);
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects();
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
|
||||
|
||||
// Register a texture (VkDescriptorSet == ImTextureID)
|
||||
// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem, please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions.
|
||||
IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout);
|
||||
|
||||
// Optional: load Vulkan functions with a custom function loader
|
||||
// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES
|
||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = NULL);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Internal / Miscellaneous Vulkan Helpers
|
||||
// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.)
|
||||
//-------------------------------------------------------------------------
|
||||
// You probably do NOT need to use or care about those functions.
|
||||
// Those functions only exist because:
|
||||
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
||||
// 2) the upcoming multi-viewport feature will need them internally.
|
||||
// Generally we avoid exposing any kind of superfluous high-level helpers in the backends,
|
||||
// but it is too much code to duplicate everywhere so we exceptionally expose them.
|
||||
//
|
||||
// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
|
||||
// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
|
||||
// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
struct ImGui_ImplVulkanH_Frame;
|
||||
struct ImGui_ImplVulkanH_Window;
|
||||
|
||||
// Helpers
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator);
|
||||
IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
|
||||
IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
|
||||
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
||||
|
||||
// Helper structure to hold the data needed by one rendering frame
|
||||
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||
// [Please zero-clear before use!]
|
||||
struct ImGui_ImplVulkanH_Frame
|
||||
{
|
||||
VkCommandPool CommandPool;
|
||||
VkCommandBuffer CommandBuffer;
|
||||
VkFence Fence;
|
||||
VkImage Backbuffer;
|
||||
VkImageView BackbufferView;
|
||||
VkFramebuffer Framebuffer;
|
||||
};
|
||||
|
||||
struct ImGui_ImplVulkanH_FrameSemaphores
|
||||
{
|
||||
VkSemaphore ImageAcquiredSemaphore;
|
||||
VkSemaphore RenderCompleteSemaphore;
|
||||
};
|
||||
|
||||
// Helper structure to hold the data needed by one rendering context into one OS window
|
||||
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||
struct ImGui_ImplVulkanH_Window
|
||||
{
|
||||
int Width;
|
||||
int Height;
|
||||
VkSwapchainKHR Swapchain;
|
||||
VkSurfaceKHR Surface;
|
||||
VkSurfaceFormatKHR SurfaceFormat;
|
||||
VkPresentModeKHR PresentMode;
|
||||
VkRenderPass RenderPass;
|
||||
VkPipeline Pipeline; // The window pipeline may uses a different VkRenderPass than the one passed in ImGui_ImplVulkan_InitInfo
|
||||
bool ClearEnable;
|
||||
VkClearValue ClearValue;
|
||||
uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
|
||||
uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
|
||||
uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
|
||||
ImGui_ImplVulkanH_Frame* Frames;
|
||||
ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores;
|
||||
|
||||
ImGui_ImplVulkanH_Window()
|
||||
{
|
||||
memset((void*)this, 0, sizeof(*this));
|
||||
PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this.
|
||||
ClearEnable = true;
|
||||
}
|
||||
};
|
||||
|
||||
3002
tjp/core/graphics/imgui-old/imgui_internal.h
Normal file
3002
tjp/core/graphics/imgui-old/imgui_internal.h
Normal file
File diff suppressed because it is too large
Load Diff
206
tjp/core/graphics/imgui-old/imgui_multiline.cpp
Normal file
206
tjp/core/graphics/imgui-old/imgui_multiline.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
#include "imgui_internal.h"
|
||||
|
||||
using namespace ImGui;
|
||||
|
||||
void ImGui_RenderMultiline(ImVector<char> &d, const char *buffer, float maxWidth_)
|
||||
{
|
||||
int size = 1;
|
||||
{
|
||||
auto *c = buffer;
|
||||
while (*c++ != 0)
|
||||
++size;
|
||||
}
|
||||
|
||||
d.resize(size*2);
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
ImFont* font = g.Font;
|
||||
|
||||
auto *out = d.Data;
|
||||
auto *in = buffer;
|
||||
auto *space = out, *newline = out;
|
||||
|
||||
char NEW_LINE = '\n';
|
||||
int bufferSize = 3;
|
||||
float maxWidth = maxWidth_ - bufferSize;
|
||||
|
||||
float width = 0, widthSinceSpace = 0;
|
||||
|
||||
while (*in != 0)
|
||||
{
|
||||
auto c = *in++;
|
||||
auto w =
|
||||
((int)c < font->IndexAdvanceX.Size ?
|
||||
font->IndexAdvanceX.Data[c] :
|
||||
font->FallbackAdvanceX);
|
||||
|
||||
width += w;
|
||||
widthSinceSpace += w;
|
||||
|
||||
if (c == ' ')
|
||||
{
|
||||
space = out;
|
||||
widthSinceSpace = 0;
|
||||
}
|
||||
else
|
||||
if (c == '\n')
|
||||
{
|
||||
space = newline = out;
|
||||
width = widthSinceSpace = 0;
|
||||
}
|
||||
|
||||
if (width > maxWidth)
|
||||
{
|
||||
if (space != newline)
|
||||
{
|
||||
*space = NEW_LINE;
|
||||
width = widthSinceSpace + w;
|
||||
widthSinceSpace = w;
|
||||
newline = space;
|
||||
|
||||
if (space == out)
|
||||
{
|
||||
out++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*out++ = NEW_LINE;
|
||||
width = w;
|
||||
widthSinceSpace = 0;
|
||||
newline = out;
|
||||
space = out;
|
||||
}
|
||||
}
|
||||
|
||||
*out++ = c;
|
||||
}
|
||||
|
||||
*out++ = 0;
|
||||
}
|
||||
|
||||
// Based on stb_to_utf8() from github.com/nothings/stb/
|
||||
inline int ImGui_W2C(char* buf, int buf_size, unsigned int c)
|
||||
{
|
||||
if (c < 0x80)
|
||||
{
|
||||
buf[0] = (char)c;
|
||||
return 1;
|
||||
}
|
||||
if (c < 0x800)
|
||||
{
|
||||
if (buf_size < 2) return 0;
|
||||
buf[0] = (char)(0xc0 + (c >> 6));
|
||||
buf[1] = (char)(0x80 + (c & 0x3f));
|
||||
return 2;
|
||||
}
|
||||
if (c < 0x10000)
|
||||
{
|
||||
if (buf_size < 3) return 0;
|
||||
buf[0] = (char)(0xe0 + (c >> 12));
|
||||
buf[1] = (char)(0x80 + ((c >> 6) & 0x3f));
|
||||
buf[2] = (char)(0x80 + ((c ) & 0x3f));
|
||||
return 3;
|
||||
}
|
||||
if (c <= 0x10FFFF)
|
||||
{
|
||||
if (buf_size < 4) return 0;
|
||||
buf[0] = (char)(0xf0 + (c >> 18));
|
||||
buf[1] = (char)(0x80 + ((c >> 12) & 0x3f));
|
||||
buf[2] = (char)(0x80 + ((c >> 6) & 0x3f));
|
||||
buf[3] = (char)(0x80 + ((c ) & 0x3f));
|
||||
return 4;
|
||||
}
|
||||
// Invalid code point, the max unicode is 0x10FFFF
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void ImGui_RenderMultiline(ImVector<char> &d, ImVector<ImWchar> &r, int &rSize, ImVector<ImWchar> &w, float maxWidth_)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImFont* font = g.Font;
|
||||
|
||||
r.resize(w.size()*2);
|
||||
d.resize(r.size()*4);
|
||||
|
||||
rSize = 0;
|
||||
|
||||
auto *outC = d.Data;
|
||||
auto *outW = r.Data;
|
||||
|
||||
auto *in = w.Data;
|
||||
auto *spaceC = outC, *newlineC = outC;
|
||||
auto *spaceW = outW, *newlineW = outW;
|
||||
|
||||
char NEW_LINE = '\n';
|
||||
int bufferSize = 3;
|
||||
float maxWidth = maxWidth_ - bufferSize;
|
||||
|
||||
float width = 0, widthSinceSpace = 0;
|
||||
while (*in != 0)
|
||||
{
|
||||
auto c = *in++;
|
||||
auto w =
|
||||
((int)c < font->IndexAdvanceX.Size ?
|
||||
font->IndexAdvanceX.Data[c] :
|
||||
font->FallbackAdvanceX);
|
||||
|
||||
width += w;
|
||||
widthSinceSpace += w;
|
||||
|
||||
if (c == ' ')
|
||||
{
|
||||
spaceC = outC; spaceW = outW;
|
||||
widthSinceSpace = 0;
|
||||
}
|
||||
else
|
||||
if (c == '\n')
|
||||
{
|
||||
spaceC = newlineC = outC;
|
||||
spaceW = newlineW = outW;
|
||||
width = widthSinceSpace = 0;
|
||||
}
|
||||
|
||||
if (width > maxWidth)
|
||||
{
|
||||
if (spaceC != newlineC)
|
||||
{
|
||||
*spaceC = NEW_LINE; *spaceW = NEW_LINE;
|
||||
|
||||
width = widthSinceSpace + w;
|
||||
widthSinceSpace = w;
|
||||
|
||||
newlineC = spaceC; newlineW = spaceW;
|
||||
|
||||
if (spaceC == outC)
|
||||
{
|
||||
outC++; outW++;
|
||||
rSize++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*outC++ = NEW_LINE; *outW++ = NEW_LINE;
|
||||
rSize++;
|
||||
|
||||
width = w;
|
||||
widthSinceSpace = 0;
|
||||
|
||||
newlineC = outC; newlineW = outW;
|
||||
spaceC = outC; spaceW = outW;
|
||||
}
|
||||
}
|
||||
|
||||
*outW++ = c;
|
||||
rSize++;
|
||||
|
||||
outC += ImGui_W2C(outC, 10, c);
|
||||
}
|
||||
|
||||
*outC++ = 0; *outW++ = 0;
|
||||
}
|
||||
|
||||
4074
tjp/core/graphics/imgui-old/imgui_tables.cpp
Normal file
4074
tjp/core/graphics/imgui-old/imgui_tables.cpp
Normal file
File diff suppressed because it is too large
Load Diff
8490
tjp/core/graphics/imgui-old/imgui_widgets.cpp
Normal file
8490
tjp/core/graphics/imgui-old/imgui_widgets.cpp
Normal file
File diff suppressed because it is too large
Load Diff
627
tjp/core/graphics/imgui-old/imstb_rectpack.h
Normal file
627
tjp/core/graphics/imgui-old/imstb_rectpack.h
Normal file
@@ -0,0 +1,627 @@
|
||||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
//
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
typedef int stbrp_coord;
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
context->extra[1].y = (1<<30);
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
1447
tjp/core/graphics/imgui-old/imstb_textedit.h
Normal file
1447
tjp/core/graphics/imgui-old/imstb_textedit.h
Normal file
File diff suppressed because it is too large
Load Diff
5085
tjp/core/graphics/imgui-old/imstb_truetype.h
Normal file
5085
tjp/core/graphics/imgui-old/imstb_truetype.h
Normal file
File diff suppressed because it is too large
Load Diff
48
tjp/core/graphics/soft/Screen+IO.h
Executable file
48
tjp/core/graphics/soft/Screen+IO.h
Executable file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "Screen.h"
|
||||
#include <iostream>
|
||||
#include <tjp/core/iterators/range.hpp>
|
||||
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
template<typename T>
|
||||
std::ostream &operator <<(std::ostream &o, const Screen<T> &s)
|
||||
{
|
||||
using namespace core::iterators;
|
||||
|
||||
auto D = "";
|
||||
|
||||
for (auto _ : range(s.dimensions.y+2))
|
||||
{
|
||||
(void)_;
|
||||
o << "-" << D;
|
||||
}
|
||||
o << std::endl;
|
||||
|
||||
for (auto y : range(s.dimensions.y))
|
||||
{
|
||||
o << "|";
|
||||
for (auto x : range(s.dimensions.x))
|
||||
{
|
||||
if (auto v = s.get({x,y}))
|
||||
o << v << D;
|
||||
else
|
||||
o << " " << D;
|
||||
}
|
||||
|
||||
o << "|" << std::endl;
|
||||
}
|
||||
|
||||
for (auto _ : range(s.dimensions.y+2))
|
||||
{
|
||||
(void)_;
|
||||
o << "-" << D;
|
||||
}
|
||||
o << std::endl;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
1
tjp/core/graphics/soft/Screen+PNG.cpp
Executable file
1
tjp/core/graphics/soft/Screen+PNG.cpp
Executable file
@@ -0,0 +1 @@
|
||||
#include "Screen+PNG.inl"
|
||||
186
tjp/core/graphics/soft/Screen+PNG.inl
Executable file
186
tjp/core/graphics/soft/Screen+PNG.inl
Executable file
@@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
#include "Screen.h"
|
||||
#include "Screen.hpp"
|
||||
#include "../STB+Image.h"
|
||||
|
||||
#include <tjp/core/math/Vector3.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
|
||||
template<typename T>
|
||||
Vector<char> toPNG(const Screen<T> &screen);
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
Vector<char> toPNG(const Screen<bool> &screen)
|
||||
{
|
||||
Vector<u8> data;
|
||||
for (auto v : screen.memory)
|
||||
data.push_back(v ? 255 : 0);
|
||||
|
||||
auto channels = 1;
|
||||
|
||||
int len;
|
||||
char *png = (char *)stbi_write_png_to_mem(
|
||||
data.data(),
|
||||
channels * screen.dimensions.x(),
|
||||
screen.dimensions.x(),
|
||||
screen.dimensions.y(),
|
||||
channels,
|
||||
&len
|
||||
);
|
||||
|
||||
Vector<char> result(png, png + len);
|
||||
|
||||
free(png);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Vector<char> toPNG(const Screen<math::Vector3<T>> &screen)
|
||||
{
|
||||
Vector<u8> data;
|
||||
for (auto v : screen.memory) {
|
||||
data.push_back(v[0] * 255);
|
||||
data.push_back(v[1] * 255);
|
||||
data.push_back(v[2] * 255);
|
||||
}
|
||||
|
||||
auto channels = 3;
|
||||
|
||||
int len;
|
||||
char *png = (char *)stbi_write_png_to_mem(
|
||||
data.data(),
|
||||
channels * screen.dimensions.x,
|
||||
screen.dimensions.x,
|
||||
screen.dimensions.y,
|
||||
channels,
|
||||
&len
|
||||
);
|
||||
|
||||
Vector<char> result(png, png + len);
|
||||
|
||||
free(png);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Screen<T> fromPNG(const Vector<char> &screen);
|
||||
|
||||
template<>
|
||||
inline
|
||||
Screen<bool> fromPNG(const Vector<char> &data)
|
||||
{
|
||||
int width, height, channels;
|
||||
|
||||
char *png = (char *)stbi_load_from_memory(
|
||||
(unsigned char *)data.data(), (int)data.size(),
|
||||
&width, &height, &channels, 0
|
||||
);
|
||||
|
||||
Screen<bool> result(
|
||||
Screen<bool>::Point { width, height }
|
||||
);
|
||||
|
||||
auto *begin = png;
|
||||
auto *end = begin + (width * height * channels);
|
||||
|
||||
int e = 0;
|
||||
for (auto *p=png; p!=end; p+= channels)
|
||||
{
|
||||
bool v = false;
|
||||
for (auto i=0; i<channels; ++i)
|
||||
{
|
||||
if (p[i] != 0)
|
||||
{
|
||||
v = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result.memory[e++] = v;
|
||||
}
|
||||
|
||||
free(png);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline
|
||||
Screen<u8> fromPNG(const Vector<char> &data)
|
||||
{
|
||||
int width, height, channels;
|
||||
|
||||
auto *png = (unsigned char *)stbi_load_from_memory(
|
||||
(unsigned char *)data.data(), (int)data.size(),
|
||||
&width, &height, &channels, 0
|
||||
);
|
||||
|
||||
Screen<u8> result(
|
||||
Screen<u8>::Point { width, height }
|
||||
);
|
||||
|
||||
auto *begin = png;
|
||||
auto *end = begin + (width * height * channels);
|
||||
|
||||
int e = 0;
|
||||
for (auto *p=png; p!=end; p+= channels)
|
||||
{
|
||||
u32 v = 0;
|
||||
for (auto i=0; i<channels; ++i)
|
||||
v += p[i];
|
||||
|
||||
v /= channels;
|
||||
|
||||
result.memory[e++] = (u8)v;
|
||||
}
|
||||
|
||||
free(png);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
Screen<math::Vector3r> fromPNG(const Vector<char> &data)
|
||||
{
|
||||
int width, height, channels;
|
||||
|
||||
char *png = (char *)stbi_load_from_memory(
|
||||
(unsigned char *)data.data(), (int)data.size(),
|
||||
&width, &height, &channels, 0
|
||||
);
|
||||
|
||||
Screen<math::Vector3r> result(
|
||||
Screen<math::Vector3r>::Point { width, height }
|
||||
);
|
||||
|
||||
auto *begin = png;
|
||||
auto *end = begin + (width * height * channels);
|
||||
int e = 0;
|
||||
for (auto *p=png; p!=end; p+= channels)
|
||||
{
|
||||
math::Vector3r v = math::Vector3r::Zero;
|
||||
for (auto i=0; i<channels && i<3; ++i)
|
||||
v[i] = p[i]/255.0;
|
||||
|
||||
result.memory[e++] = v;
|
||||
|
||||
}
|
||||
|
||||
free(png);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
21
tjp/core/graphics/soft/Screen+and.inl
Executable file
21
tjp/core/graphics/soft/Screen+and.inl
Executable file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Screen.h"
|
||||
|
||||
#include <tjp/core/iterators/enumerate.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
template<typename T, typename U>
|
||||
Screen<T> &and_(Screen<T> &lhs, const Screen<U> &rhs)
|
||||
{
|
||||
for (auto i=0; i<rhs.memory.size(); ++i)
|
||||
if (!rhs.memory.at(i))
|
||||
lhs.memory[i] = 0;
|
||||
|
||||
return lhs;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
39
tjp/core/graphics/soft/Screen+dilate.inl
Executable file
39
tjp/core/graphics/soft/Screen+dilate.inl
Executable file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <tjp/core/iterators/range.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
template<typename T>
|
||||
Screen<T> dilate(const Screen<T> &screen)
|
||||
{
|
||||
auto copy = screen;
|
||||
for (auto y : range(1, screen.dimensions.y()-1))
|
||||
{
|
||||
for (auto x : range(1, screen.dimensions.x()-1))
|
||||
{
|
||||
bool shouldDilate = false;
|
||||
auto dx_ = 0, dy_ = 0;
|
||||
|
||||
for (int dy = -1; dy <= 1; ++dy) {
|
||||
for (int dx = -1; dx <= 1; ++dx) {
|
||||
if (screen.ref({x + dx, y + dy})) {
|
||||
dx_ = dx; dy_ = dy;
|
||||
shouldDilate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shouldDilate) break;
|
||||
}
|
||||
|
||||
if (shouldDilate)
|
||||
copy.set({x, y}, screen.ref({x + dx_, y + dy_}));
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
40
tjp/core/graphics/soft/Screen+erode.inl
Executable file
40
tjp/core/graphics/soft/Screen+erode.inl
Executable file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "Screen.h"
|
||||
#include <tjp/core/iterators/range.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
template<typename T>
|
||||
Screen<T> erode(const Screen<T> &screen)
|
||||
{
|
||||
auto copy = screen;
|
||||
for (auto y : range(1, screen.dimensions.y-1))
|
||||
{
|
||||
for (auto x : range(1, screen.dimensions.x-1))
|
||||
{
|
||||
bool shouldErode = true;
|
||||
auto dx_ = 0, dy_ = 0;
|
||||
|
||||
for (int dy = -1; dy <= 1; ++dy) {
|
||||
for (int dx = -1; dx <= 1; ++dx) {
|
||||
if (!screen.at({x + dx, y + dy})) {
|
||||
dx_ = dx; dy_ = dy;
|
||||
shouldErode = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!shouldErode) break;
|
||||
}
|
||||
|
||||
if (shouldErode)
|
||||
copy.set({x, y}, screen.at({x + dx_, y + dy_}));
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
43
tjp/core/graphics/soft/Screen+find_path.inl
Executable file
43
tjp/core/graphics/soft/Screen+find_path.inl
Executable file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "pathfinders.h"
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
template<typename U>
|
||||
Vector<int> find_path(const Screen<u8> &screen, const U &start, const U &end)
|
||||
{
|
||||
Vector<int> path;
|
||||
path.resize(16384);
|
||||
|
||||
auto pathSize =
|
||||
// BFSFindPathDiag(
|
||||
AStarFindPathDiag(
|
||||
(int)start.x(), (int)start.y(),
|
||||
(int)end.x(), (int)end.y(),
|
||||
screen.memory.data(),
|
||||
screen.dimensions.x(),
|
||||
screen.dimensions.y(),
|
||||
path.data(),
|
||||
(int)path.size()
|
||||
);
|
||||
|
||||
if (pathSize < 0)
|
||||
pathSize = 0;
|
||||
|
||||
path.resize(pathSize);
|
||||
return path;
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
Vector<int> find_path(const Screen<T> &screen, const U &start, const U &end)
|
||||
{
|
||||
Screen<u8> map(screen.dimensions);
|
||||
|
||||
for (auto i=0; i<screen.memory.size(); ++i)
|
||||
map.memory[i] = screen.memory.at(i);
|
||||
|
||||
return find_path(map, start, end);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
8
tjp/core/graphics/soft/Screen.h
Executable file
8
tjp/core/graphics/soft/Screen.h
Executable file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
template<typename T>
|
||||
struct Screen;
|
||||
|
||||
} // namespace
|
||||
169
tjp/core/graphics/soft/Screen.hpp
Executable file
169
tjp/core/graphics/soft/Screen.hpp
Executable file
@@ -0,0 +1,169 @@
|
||||
#pragma once
|
||||
|
||||
#include "Screen.h"
|
||||
|
||||
#include <tjp/core/math/Vector2.hpp>
|
||||
#include <tjp/core/math/Vector2.inl>
|
||||
#include <tjp/core/assert/debug_assert.h>
|
||||
#include <tjp/core/containers/Vector.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
template<typename T>
|
||||
struct Screen {
|
||||
using Point = core::math::Vector2i;
|
||||
using Real = core::math::Real;
|
||||
using Interpolation = core::math::Vector2<Real>;
|
||||
|
||||
using Memory = Vector<T>;
|
||||
using const_reference = typename Memory::const_reference;
|
||||
using reference = typename Memory::reference;
|
||||
using value_type = T;
|
||||
|
||||
Memory memory;
|
||||
Point dimensions;
|
||||
|
||||
Screen() :
|
||||
dimensions({0,0})
|
||||
{}
|
||||
|
||||
Screen(const Screen &rhs) :
|
||||
memory(rhs.memory),
|
||||
dimensions(rhs.dimensions)
|
||||
{
|
||||
}
|
||||
|
||||
Screen(const Point &dimensions_) : Screen()
|
||||
{
|
||||
resize(dimensions_);
|
||||
}
|
||||
|
||||
Screen(Screen &&rhs) :
|
||||
memory(std::move(rhs.memory)),
|
||||
dimensions(std::move(rhs.dimensions))
|
||||
{
|
||||
}
|
||||
|
||||
void resize(const Point &dimensions_)
|
||||
{
|
||||
dimensions = dimensions_;
|
||||
memory.resize(dimensions[0] * dimensions[1]);
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return memory.empty();
|
||||
}
|
||||
|
||||
auto &operator=(Screen<T> &©)
|
||||
{
|
||||
memory = std::move(copy.memory);
|
||||
dimensions = std::move(copy.dimensions);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto &operator=(const Screen<T> ©)
|
||||
{
|
||||
memory = copy.memory;
|
||||
dimensions = copy.dimensions;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto index(const Point &p) const
|
||||
{
|
||||
return p[1] * dimensions[0] + p[0];
|
||||
}
|
||||
|
||||
reference ref(const Point &p)
|
||||
{
|
||||
debug_assert(has(p));
|
||||
|
||||
auto i = index(p);
|
||||
return memory[i];
|
||||
}
|
||||
|
||||
const_reference ref(const Point &p) const
|
||||
{
|
||||
debug_assert(has(p));
|
||||
|
||||
auto i = index(p);
|
||||
return memory[i];
|
||||
}
|
||||
|
||||
value_type get(const Point &p) const
|
||||
{
|
||||
debug_assert(has(p));
|
||||
|
||||
return memory[p[1] * dimensions[0] + p[0]];
|
||||
}
|
||||
|
||||
Point clamp(const Point &p) const
|
||||
{
|
||||
return Point {
|
||||
(p[0] < 0) ? 0 :
|
||||
(p[0] >= dimensions[0]) ? dimensions[0] - 1 :
|
||||
p[0],
|
||||
(p[1] < 0) ? 0 :
|
||||
(p[1] >= dimensions[1]) ? dimensions[1] - 1 :
|
||||
p[1]
|
||||
} ;
|
||||
}
|
||||
|
||||
auto interpolate(const Interpolation &p_) const
|
||||
{
|
||||
auto p = mul(p_, dimensions.asType<Real>());
|
||||
auto p0 = Point { (int)std::floor(p[0]), (int)std::floor(p[1]) };
|
||||
|
||||
Point ps[4] = {
|
||||
p0,
|
||||
{ p0[0] + 1, p0[1] },
|
||||
{ p0[0], p0[1] + 1 },
|
||||
{ p0[0] + 1, p0[1] + 1 }
|
||||
};
|
||||
|
||||
auto sqrt_2 = std::sqrt(2);
|
||||
|
||||
Real wv = 0;
|
||||
Real w = 0;
|
||||
for (auto i=0; i<4; ++i)
|
||||
{
|
||||
auto pv = get(clamp(ps[i]));
|
||||
|
||||
auto pw = sqrt_2 - (p - ps[i].asType<Real>()).length();
|
||||
auto pwv = pw * pv;
|
||||
|
||||
w += pw;
|
||||
wv += pwv;
|
||||
}
|
||||
|
||||
auto v = wv / w;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void set(const Point &p, const T &t)
|
||||
{
|
||||
debug_assert(has(p));
|
||||
|
||||
auto i = index(p);
|
||||
memory[i] = t;
|
||||
}
|
||||
|
||||
bool has(const Point &p) const
|
||||
{
|
||||
return
|
||||
p[0] >= 0 && p[0] < dimensions[0] &&
|
||||
p[1] >= 0 && p[1] < dimensions[1];
|
||||
}
|
||||
|
||||
void clear(const T &value)
|
||||
{
|
||||
memory.assign(memory.size(), value);
|
||||
}
|
||||
} ;
|
||||
|
||||
} // namespace
|
||||
56
tjp/core/graphics/soft/_tests/Screen.cpp
Executable file
56
tjp/core/graphics/soft/_tests/Screen.cpp
Executable file
@@ -0,0 +1,56 @@
|
||||
#include "../Screen.hpp"
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <tjp/core/iterators/range.hpp>
|
||||
|
||||
namespace tjp::core::graphics::soft {
|
||||
|
||||
using namespace core::iterators;
|
||||
|
||||
SCENARIO("screen")
|
||||
{
|
||||
GIVEN("a screen")
|
||||
{
|
||||
Screen<bool> s({10,10});
|
||||
|
||||
REQUIRE(s.has({-1, 0}) == false);
|
||||
REQUIRE(s.has({0, 0}) == true);
|
||||
REQUIRE(s.has({10, 0}) == false);
|
||||
REQUIRE(s.has({9,9}) == true);
|
||||
}
|
||||
|
||||
GIVEN("a screen")
|
||||
{
|
||||
Screen<bool> s({10,10});
|
||||
|
||||
WHEN("clears")
|
||||
{
|
||||
s.clear(false);
|
||||
for (auto i : range(s.dimensions.x))
|
||||
{
|
||||
for (auto j : range(s.dimensions.y))
|
||||
{
|
||||
REQUIRE(s.get({i,j}) == false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("clear and set")
|
||||
{
|
||||
s.clear(false);
|
||||
REQUIRE(s.get({5,5}) == false);
|
||||
s.set({5,5}, true);
|
||||
|
||||
REQUIRE(s.get({5,5}) == true);
|
||||
REQUIRE(s.get({4,5}) == false);
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("a screen")
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
604
tjp/core/graphics/soft/pathfinders.cpp
Normal file
604
tjp/core/graphics/soft/pathfinders.cpp
Normal file
@@ -0,0 +1,604 @@
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <tuple>
|
||||
#include <cstdlib>
|
||||
#include <climits>
|
||||
|
||||
#include <random>
|
||||
//#include <boost/random/random_device.hpp>
|
||||
//#include <boost/random/uniform_int_distribution.hpp>
|
||||
|
||||
|
||||
// https://github.com/XinosZeng/pathfinding-AStarVar
|
||||
|
||||
#include "pathfinders.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static int ExploredNodes;
|
||||
static vector<int> Landmarks;
|
||||
static vector<vector<int>> LD;
|
||||
|
||||
int BFSFindPath(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
d[startPos] = 0;
|
||||
queue<int> q;
|
||||
q.push(startPos);
|
||||
while (!q.empty()) {
|
||||
int u = q.front(); q.pop(); ExploredNodes++;
|
||||
for (auto e : {+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if ((e == 1 && (v % nMapWidth == 0)) || (e == -1 && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] == INT_MAX && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
int BFSFindPathDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
queue<int> q;
|
||||
d[startPos] = 0;
|
||||
q.push(startPos);
|
||||
while (!q.empty()) {
|
||||
int u = q.front(); q.pop(); ExploredNodes++;
|
||||
for (auto e : {-nMapWidth-1, -nMapWidth+1, +nMapWidth-1, +nMapWidth+1,
|
||||
+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if (((e == 1 || e == -nMapWidth+1 || e == nMapWidth+1) && (v % nMapWidth == 0))
|
||||
|| ((e == -1 || e == -nMapWidth-1 || e == nMapWidth-1) && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] == INT_MAX && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos]; // buffer size too small
|
||||
}
|
||||
|
||||
int AStarFindPath(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
auto h = [=](int u) -> int { // lower bound distance to target from u
|
||||
int x = u % nMapWidth, y = u / nMapWidth;
|
||||
return abs(x-nTargetX) + abs(y-nTargetY);
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
int discovered = 0; ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
priority_queue<tuple<int, int, int>,
|
||||
vector<tuple<int, int, int>>,
|
||||
greater<tuple<int, int, int>>> pq; // A* with tie breaking
|
||||
d[startPos] = 0;
|
||||
pq.push(make_tuple(0 + h(startPos), 0, startPos));
|
||||
while (!pq.empty()) {
|
||||
int u = get<2>(pq.top()); pq.pop(); ExploredNodes++;
|
||||
for (auto e : {+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if ((e == 1 && (v % nMapWidth == 0)) || (e == -1 && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] > d[u] + 1 && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
pq.push(make_tuple(d[v] + h(v), ++discovered, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos]; // buffer size too small
|
||||
}
|
||||
|
||||
int AStarFindPathDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
// auto h = [=](int u) -> int { // lower bound distance to target from u
|
||||
// int x = u % nMapWidth, y = u / nMapWidth;
|
||||
// return max(abs(x-nTargetX), abs(y-nTargetY));
|
||||
// };
|
||||
|
||||
auto h = [=](int u) -> int {
|
||||
int x = u % nMapWidth, y = u / nMapWidth;
|
||||
int dx = abs(x - nTargetX), dy = abs(y - nTargetY);
|
||||
return (dx + dy) + (sqrt(2) - 2) * min(dx, dy);
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
int discovered = 0; ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
priority_queue<tuple<int, int, int>,
|
||||
vector<tuple<int, int, int>>,
|
||||
greater<tuple<int, int, int>>> pq; // A* with tie breaking
|
||||
d[startPos] = 0;
|
||||
pq.push(make_tuple(0 + h(startPos), 0, startPos));
|
||||
while (!pq.empty()) {
|
||||
int u = get<2>(pq.top()); pq.pop(); ExploredNodes++;
|
||||
for (auto e : {-nMapWidth-1, -nMapWidth+1, +nMapWidth-1, +nMapWidth+1,
|
||||
+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if (((e == 1 || e == -nMapWidth+1 || e == nMapWidth+1) && (v % nMapWidth == 0))
|
||||
|| ((e == -1 || e == -nMapWidth-1 || e == nMapWidth-1) && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] > d[u] + 1 && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
pq.push(make_tuple(d[v] + h(v), ++discovered, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos]; // buffer size too small
|
||||
}
|
||||
|
||||
void InitializeLandmarks(int k, const unsigned char* pMap, const int nMapWidth, const int nMapHeight) {
|
||||
|
||||
vector<int> traversable;
|
||||
for (int i = 0; i < nMapWidth; i++)
|
||||
for (int j = 0; j < nMapHeight; j++)
|
||||
if (pMap[nMapWidth*j + i])
|
||||
traversable.push_back(nMapWidth*j + i);
|
||||
|
||||
while (Landmarks.size() < k) {
|
||||
|
||||
if (Landmarks.empty()) {
|
||||
std::mt19937 rng;
|
||||
uniform_int_distribution<> uniform(0, traversable.size() - 1);
|
||||
Landmarks.push_back(traversable[uniform(rng)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
queue<int> q;
|
||||
for (auto s : Landmarks) {
|
||||
d[s] = 0;
|
||||
q.push(s);
|
||||
}
|
||||
int farthest = -1, maxdist = -1;
|
||||
while (!q.empty()) {
|
||||
int u = q.front(); q.pop();
|
||||
if (d[u] > maxdist)
|
||||
maxdist = d[u], farthest = u;
|
||||
for (auto e : {+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if ((e == 1 && (v % nMapWidth == 0)) || (e == -1 && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] == INT_MAX && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Landmarks.push_back(farthest); // works well when the graph is not too disconnected
|
||||
}
|
||||
|
||||
LD.resize(Landmarks.size());
|
||||
for (int i = 0; i < Landmarks.size(); i++) {
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
vector<int> p(n); LD[i].resize(n, INT_MAX);
|
||||
queue<int> q;
|
||||
int s = Landmarks[i];
|
||||
LD[i][s] = 0;
|
||||
q.push(s);
|
||||
while (!q.empty()) {
|
||||
int u = q.front(); q.pop();
|
||||
for (auto e : {+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if ((e == 1 && (v % nMapWidth == 0)) || (e == -1 && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && LD[i][v] == INT_MAX && pMap[v]) {
|
||||
p[v] = u;
|
||||
LD[i][v] = LD[i][u] + 1;
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int AStarFindPathLandmarks(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
auto h = [=](int u) { // lower bound distance to target from u
|
||||
int m = 0;
|
||||
for (int i = 0; i < Landmarks.size(); i++) // global vector<int> Landmarks
|
||||
m = max(m, LD[i][targetPos] - LD[i][u]); // global vector<vector<int>> LD
|
||||
return m;
|
||||
};
|
||||
|
||||
int discovered = 0; ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
priority_queue<tuple<int, int, int>,
|
||||
vector<tuple<int, int, int>>,
|
||||
greater<tuple<int, int, int>>> pq; // A* with tie breaking
|
||||
d[startPos] = 0;
|
||||
pq.push(make_tuple(0 + h(startPos), 0, startPos));
|
||||
while (!pq.empty()) {
|
||||
int u = get<2>(pq.top()); pq.pop(); ExploredNodes++;
|
||||
for (auto e : {+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if ((e == 1 && (v % nMapWidth == 0)) || (e == -1 && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] > d[u] + 1 && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
pq.push(make_tuple(d[v] + h(v), ++discovered, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos]; // buffer size too small
|
||||
}
|
||||
|
||||
void InitializeLandmarksDiag(int k, const unsigned char* pMap, const int nMapWidth, const int nMapHeight) {
|
||||
|
||||
vector<int> traversable;
|
||||
for (int i = 0; i < nMapWidth; i++)
|
||||
for (int j = 0; j < nMapHeight; j++)
|
||||
if (pMap[nMapWidth*j + i])
|
||||
traversable.push_back(nMapWidth*j + i);
|
||||
|
||||
while (Landmarks.size() < k) {
|
||||
|
||||
if (Landmarks.empty()) {
|
||||
std::mt19937 rng;
|
||||
uniform_int_distribution<> uniform(0, traversable.size() - 1);
|
||||
Landmarks.push_back(traversable[uniform(rng)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
queue<int> q;
|
||||
for (auto s : Landmarks) {
|
||||
d[s] = 0;
|
||||
q.push(s);
|
||||
}
|
||||
int farthest = -1, maxdist = -1;
|
||||
while (!q.empty()) {
|
||||
int u = q.front(); q.pop();
|
||||
if (d[u] > maxdist)
|
||||
maxdist = d[u], farthest = u;
|
||||
for (auto e : {-nMapWidth-1, -nMapWidth+1, +nMapWidth-1, +nMapWidth+1,
|
||||
+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if (((e == 1 || e == -nMapWidth+1 || e == nMapWidth+1) && (v % nMapWidth == 0))
|
||||
|| ((e == -1 || e == -nMapWidth-1 || e == nMapWidth-1) && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] == INT_MAX && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Landmarks.push_back(farthest); // works well when the graph is not too disconnected
|
||||
}
|
||||
|
||||
LD.resize(Landmarks.size());
|
||||
for (int i = 0; i < Landmarks.size(); i++) {
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
vector<int> p(n); LD[i].resize(n, INT_MAX);
|
||||
queue<int> q;
|
||||
int s = Landmarks[i];
|
||||
LD[i][s] = 0;
|
||||
q.push(s);
|
||||
while (!q.empty()) {
|
||||
int u = q.front(); q.pop();
|
||||
for (auto e : {-nMapWidth-1, -nMapWidth+1, +nMapWidth-1, +nMapWidth+1,
|
||||
+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if (((e == 1 || e == -nMapWidth+1 || e == nMapWidth+1) && (v % nMapWidth == 0))
|
||||
|| ((e == -1 || e == -nMapWidth-1 || e == nMapWidth-1) && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && LD[i][v] == INT_MAX && pMap[v]) {
|
||||
p[v] = u;
|
||||
LD[i][v] = LD[i][u] + 1;
|
||||
q.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int AStarFindPathLandmarksDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
auto h = [=](int u) { // lower bound distance to target from u
|
||||
int m = 0;
|
||||
for (int i = 0; i < Landmarks.size(); i++) // global vector<int> Landmarks
|
||||
m = max(m, LD[i][targetPos] - LD[i][u]); // global vector<vector<int>> LD
|
||||
return m;
|
||||
};
|
||||
|
||||
int discovered = 0; ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
priority_queue<tuple<int, int, int>,
|
||||
vector<tuple<int, int, int>>,
|
||||
greater<tuple<int, int, int>>> pq; // A* with tie breaking
|
||||
d[startPos] = 0;
|
||||
pq.push(make_tuple(0 + h(startPos), 0, startPos));
|
||||
while (!pq.empty()) {
|
||||
int u = get<2>(pq.top()); pq.pop(); ExploredNodes++;
|
||||
for (auto e : {-nMapWidth-1, -nMapWidth+1, +nMapWidth-1, +nMapWidth+1,
|
||||
+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if (((e == 1 || e == -nMapWidth+1 || e == nMapWidth+1) && (v % nMapWidth == 0))
|
||||
|| ((e == -1 || e == -nMapWidth-1 || e == nMapWidth-1) && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] > d[u] + 1 && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
pq.push(make_tuple(d[v] + h(v), ++discovered, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos]; // buffer size too small
|
||||
}
|
||||
|
||||
int AStarFindPathNoTie(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
auto h = [=](int u) { // lower bound distance to target from u
|
||||
int x = u % nMapWidth, y = u / nMapWidth;
|
||||
return abs(x-nTargetX) + abs(y-nTargetY);
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
priority_queue<pair<int, int>,
|
||||
vector<pair<int, int>>,
|
||||
greater<pair<int, int>>> pq;
|
||||
d[startPos] = 0;
|
||||
pq.push(make_pair(0 + h(startPos), startPos));
|
||||
while (!pq.empty()) {
|
||||
int u = pq.top().second; pq.pop(); ExploredNodes++;
|
||||
for (auto e : {+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if ((e == 1 && (v % nMapWidth == 0)) || (e == -1 && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] > d[u] + 1 && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
pq.push(make_pair(d[v] + h(v), v));
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos]; // buffer size too small
|
||||
}
|
||||
|
||||
int AStarFindPathNoTieDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize) {
|
||||
|
||||
auto idx = [nMapWidth](int x, int y) {
|
||||
return x + y*nMapWidth;
|
||||
};
|
||||
|
||||
auto h = [=](int u) { // lower bound distance to target from u
|
||||
int x = u % nMapWidth, y = u / nMapWidth;
|
||||
return max(abs(x-nTargetX), abs(y-nTargetY));
|
||||
};
|
||||
|
||||
const int n = nMapWidth*nMapHeight;
|
||||
const int startPos = idx(nStartX, nStartY), targetPos = idx(nTargetX, nTargetY);
|
||||
|
||||
ExploredNodes = 0;
|
||||
vector<int> p(n), d(n, INT_MAX);
|
||||
priority_queue<pair<int, int>,
|
||||
vector<pair<int, int>>,
|
||||
greater<pair<int, int>>> pq;
|
||||
d[startPos] = 0;
|
||||
pq.push(make_pair(0 + h(startPos), startPos));
|
||||
while (!pq.empty()) {
|
||||
int u = pq.top().second; pq.pop(); ExploredNodes++;
|
||||
for (auto e : {-nMapWidth-1, -nMapWidth+1, +nMapWidth-1, +nMapWidth+1,
|
||||
+1, -1, +nMapWidth, -nMapWidth}) {
|
||||
int v = u + e;
|
||||
if (((e == 1 || e == -nMapWidth+1 || e == nMapWidth+1) && (v % nMapWidth == 0))
|
||||
|| ((e == -1 || e == -nMapWidth-1 || e == nMapWidth-1) && (u % nMapWidth == 0)))
|
||||
continue;
|
||||
if (0 <= v && v < n && d[v] > d[u] + 1 && pMap[v]) {
|
||||
p[v] = u;
|
||||
d[v] = d[u] + 1;
|
||||
if (v == targetPos)
|
||||
goto end;
|
||||
pq.push(make_pair(d[v] + h(v), v));
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
if (d[targetPos] == INT_MAX) {
|
||||
return -1;
|
||||
} else if (d[targetPos] <= nOutBufferSize) {
|
||||
int curr = targetPos;
|
||||
for (int i = d[targetPos] - 1; i >= 0; i--) {
|
||||
pOutBuffer[i] = curr;
|
||||
curr = p[curr];
|
||||
}
|
||||
return d[targetPos];
|
||||
}
|
||||
|
||||
return d[targetPos]; // buffer size too small
|
||||
}
|
||||
48
tjp/core/graphics/soft/pathfinders.h
Normal file
48
tjp/core/graphics/soft/pathfinders.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef PATHFINDERS_H
|
||||
#define PATHFINDERS_H
|
||||
|
||||
int BFSFindPath(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
int BFSFindPathDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
int AStarFindPath(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
int AStarFindPathDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
void InitializeLandmarks(int k, const unsigned char* pMap, const int nMapWidth, const int nMapHeight);
|
||||
|
||||
int AStarFindPathLandmarks(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
void InitializeLandmarksDiag(int k, const unsigned char* pMap, const int nMapWidth, const int nMapHeight);
|
||||
|
||||
int AStarFindPathLandmarksDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
int AStarFindPathNoTie(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
int AStarFindPathNoTieDiag(const int nStartX, const int nStartY,
|
||||
const int nTargetX, const int nTargetY,
|
||||
const unsigned char* pMap, const int nMapWidth, const int nMapHeight,
|
||||
int* pOutBuffer, const int nOutBufferSize);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user