diff --git a/.vscode/launch.json b/.vscode/launch.json index 2aa3dfc..1ed85e3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,8 +11,8 @@ "name": "Launch currently open script", "type": "php", "request": "launch", - "program": "${file}", - "cwd": "${fileDirname}", + "program": "${workspaceFolder}/examples/print.php", + "cwd": "${workspaceFolder}", "port": 9055 } ] diff --git a/examples/print.php b/examples/print.php new file mode 100644 index 0000000..91ea267 --- /dev/null +++ b/examples/print.php @@ -0,0 +1,21 @@ +useGpu(); + +echo $opencl; + +$pathDepth = new PathDepth([ + "total" => 12 +]); + +$depth = new Path([ + "pathdepth" => $pathDepth +]); + +echo $depth; diff --git a/examples/test.php b/examples/test.php deleted file mode 100644 index e4a8deb..0000000 --- a/examples/test.php +++ /dev/null @@ -1,8 +0,0 @@ - \ No newline at end of file diff --git a/src/core/Base.php b/src/core/Base.php new file mode 100644 index 0000000..3afd41a --- /dev/null +++ b/src/core/Base.php @@ -0,0 +1,18 @@ + $value) { + $this->$name = $value; + } + } + } +} diff --git a/src/scene/BaseCfg.php b/src/scene/BaseCfg.php new file mode 100644 index 0000000..eb7c224 --- /dev/null +++ b/src/scene/BaseCfg.php @@ -0,0 +1,58 @@ +toString(); + } + + public function toString($parentClassName = false) + { + $object = new \ReflectionClass($this); + $properties = $object->getProperties(); + + //获取类名 -> 去除命名空间 -> 转成全小写 + $className = get_called_class(); + $className = strtolower(array_reverse(explode('\\', $className))[0]); + if (!empty($parentClassName)) { + $className = "{$parentClassName}.$className"; + } + + $ret = ""; + foreach ($properties as $item) { + + $item->setAccessible(true); + + + //获取属性名称,并根据驼峰规则截开后从新用‘.’连接 + $name = $item->getName(); + $name = implode(".", array_map('strtolower', StringHelper::camelStrToArray($name))); + + $value = $item->getValue($this); + + if (is_string($value)) { + $ret .= "{$className}.{$name} = \"{$value}\"\n"; + } else if (is_integer($value)) { + $ret .= "{$className}.{$name} = {$value}\n"; + } else if (is_bool($value)) { + $value = $value ? 1 : 0; + $ret .= "{$className}.{$name} = {$value}\n"; + } else if (is_object($value) && $value instanceof BaseCfg) { + $ret .= $value->toString($className); + } else if(is_null($value)){ + $ret .= "{$className}.{$name} = \"null\"\n"; + } else + { + $ret .= "{$className}.{$name} = \"unknow type\"\n"; + } + } + return $ret; + } +} diff --git a/src/scene/OpenCL.php b/src/scene/OpenCL.php new file mode 100644 index 0000000..3c945b6 --- /dev/null +++ b/src/scene/OpenCL.php @@ -0,0 +1,37 @@ +cpuUse = self::OPEN; + $this->gpuUse = self::CLOSE; + } + + /** + * 使用gpu渲染 + */ + public function useGpu(){ + $this->cpuUse = self::CLOSE; + $this->gpuUse = self::OPEN; + } +} diff --git a/src/scene/Path.php b/src/scene/Path.php new file mode 100644 index 0000000..8dd2ae5 --- /dev/null +++ b/src/scene/Path.php @@ -0,0 +1,9 @@ += 65) && (ord($functionNameStr[$i]) <= 122)) && ($functionNameStr[$i] != "_")) { + echo '解析错误: 函数名称 存在非法字符 “' . $functionNameStr[$i] . '”' . "\n"; + return null; + } + } + + /* + 将函数名字符串,以大写的首字母为分割,转换成数组 + */ + for ($i = 0; $i < $strLen; $i++) { + + $functionNameTemp[] = $functionNameStr[$i]; + if (((ord(substr($functionNameStr, $i + 1, 1)) >= 65) && (ord(substr($functionNameStr, $i + 1, 1)) <= 90)) || ($i == $strLen - 1)) { + $functionNameTemp = implode($functionNameTemp); + $functionNameArray[] = $functionNameTemp; + $functionNameTemp = null; + } + } + + return $functionNameArray; + } else { + echo '解析错误:函数名称字符串不能为空' . "\n"; + return null; + } + } + + /** + * 把驼峰命名字符串截成数组 + */ + static public function camelStrToArray($str) + { + if (!is_string($str)) { + throw new \Exception("Expected parameter 2 to be an string"); + } + + return preg_split("/(?=[A-Z])/", $str); + } +}