mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-11 14:21:52 +09:00
LibGDX, here I am.
This commit is contained in:
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.sudoplay.joise.module.Module;
|
||||
import com.sudoplay.joise.module.SeedableModule;
|
||||
import com.sudoplay.util.Assert;
|
||||
|
||||
public class Joise {
|
||||
|
||||
private Module module;
|
||||
private ModuleMap moduleMap;
|
||||
private HashMap<String, ArrayList<SeedableModule>> seedMap = new HashMap<String, ArrayList<SeedableModule>>();
|
||||
|
||||
/**
|
||||
* Creates a new instance of Joise with the supplied module chain.
|
||||
* <p>
|
||||
* This method duplicates the module chain by first converting the chain to a
|
||||
* {@link ModuleMap}, then converting it back to a {@link Module} while
|
||||
* mapping any seed names to the seedmap.
|
||||
* <p>
|
||||
* Changes made to the original module passed in will not be reflected in this
|
||||
* instance of Joise.
|
||||
*
|
||||
* @param module
|
||||
*/
|
||||
public Joise(Module module) {
|
||||
Assert.notNull(module);
|
||||
moduleMap = module.getModuleMap();
|
||||
this.module = fromModuleMap(moduleMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Joise from the supplied {@link ModuleMap}.
|
||||
* <p>
|
||||
* This method duplicates the module map by first converting the map to a
|
||||
* {@link Module}, then converting it back to a module map. Seed names are
|
||||
* mapped during the conversion from map to module.
|
||||
* <p>
|
||||
* Changes made to the original module map passed in will not be reflected in
|
||||
* this instance of Joise.
|
||||
*
|
||||
* @param moduleMap
|
||||
*/
|
||||
public Joise(ModuleMap moduleMap) {
|
||||
Assert.notNull(moduleMap);
|
||||
this.module = fromModuleMap(moduleMap);
|
||||
this.moduleMap = module.getModuleMap();
|
||||
}
|
||||
|
||||
private Module fromModuleMap(ModuleMap map) {
|
||||
try {
|
||||
ModuleInstanceMap im = new ModuleInstanceMap();
|
||||
Iterator<Entry<String, ModulePropertyMap>> it = map.mapIterator();
|
||||
Module module = null;
|
||||
while (it.hasNext()) {
|
||||
Entry<String, ModulePropertyMap> e = it.next();
|
||||
ModulePropertyMap props = e.getValue();
|
||||
String moduleName = "com.sudoplay.joise.module." + props.get("module");
|
||||
module = (Module) Class.forName(moduleName).newInstance();
|
||||
module.buildFromPropertyMap(props, im);
|
||||
if (module instanceof SeedableModule
|
||||
&& ((SeedableModule) module).hasSeedName()) {
|
||||
SeedableModule sm = (SeedableModule) module;
|
||||
String seedName = sm.getSeedName();
|
||||
|
||||
ArrayList<SeedableModule> list = seedMap.get(seedName);
|
||||
if (list == null) {
|
||||
list = new ArrayList<SeedableModule>();
|
||||
seedMap.put(seedName, list);
|
||||
}
|
||||
list.add(sm);
|
||||
}
|
||||
im.put(e.getKey(), module);
|
||||
}
|
||||
return module;
|
||||
} catch (Exception e) {
|
||||
throw new JoiseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seed of the module linked by seedName.
|
||||
*
|
||||
* @param seedName
|
||||
* @param seed
|
||||
* @throws IllegalStateException
|
||||
* if the seed name is not found in the seed map
|
||||
*/
|
||||
public void setSeed(String seedName, long seed) {
|
||||
ArrayList<SeedableModule> list = seedMap.get(seedName);
|
||||
if (list == null || list.isEmpty()) {
|
||||
throw new IllegalStateException("Seed name not found: " + seedName);
|
||||
}
|
||||
for (SeedableModule sm : list) {
|
||||
sm.setSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasSeed(String seedName) {
|
||||
return seedMap.get(seedName) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the stored module map for this Joise
|
||||
*/
|
||||
public ModuleMap getModuleMap() {
|
||||
return moduleMap;
|
||||
}
|
||||
|
||||
public double get(double x, double y) {
|
||||
return module.get(x, y);
|
||||
}
|
||||
|
||||
public double get(double x, double y, double z) {
|
||||
return module.get(x, y, z);
|
||||
}
|
||||
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return module.get(x, y, z, w);
|
||||
}
|
||||
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return module.get(x, y, z, w, u, v);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class JoiseException extends RuntimeException {
|
||||
|
||||
public JoiseException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public JoiseException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public JoiseException(String msg, Exception e) {
|
||||
super(msg, e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.sudoplay.joise.module.Module;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ModuleInstanceMap extends HashMap<String, Module> {
|
||||
|
||||
@Override
|
||||
public Module put(String id, Module module) {
|
||||
if (id == null) {
|
||||
throw new NullPointerException("null id");
|
||||
}
|
||||
if (module == null) {
|
||||
throw new NullPointerException("null module, id=" + id);
|
||||
}
|
||||
return super.put(id, module);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module get(Object key) {
|
||||
Module module = super.get(key);
|
||||
if (module == null) {
|
||||
throw new NullPointerException("null module, id=" + key);
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
public boolean contains(String id) {
|
||||
return super.get(id) != null;
|
||||
}
|
||||
|
||||
public Iterator<Entry<String, Module>> iterator() {
|
||||
return super.entrySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[");
|
||||
|
||||
Iterator<Entry<String, Module>> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, Module> e = it.next();
|
||||
sb.append("[");
|
||||
sb.append(e.getKey());
|
||||
sb.append("|");
|
||||
sb.append(e.getValue());
|
||||
sb.append("]");
|
||||
}
|
||||
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ModuleMap extends LinkedHashMap<String, ModulePropertyMap> {
|
||||
|
||||
@Override
|
||||
public ModulePropertyMap put(String module, ModulePropertyMap propertyMap) {
|
||||
if (propertyMap == null) {
|
||||
throw new NullPointerException("property map for module [" + module
|
||||
+ "] null");
|
||||
}
|
||||
return super.put(module, propertyMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModulePropertyMap get(Object key) {
|
||||
ModulePropertyMap props = super.get(key);
|
||||
if (props == null) {
|
||||
throw new NullPointerException("property map [" + key + "] null");
|
||||
}
|
||||
return super.get(key);
|
||||
}
|
||||
|
||||
public boolean contains(String id) {
|
||||
return super.get(id) != null;
|
||||
}
|
||||
|
||||
public Iterator<Entry<String, ModulePropertyMap>> mapIterator() {
|
||||
return super.entrySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[");
|
||||
|
||||
Iterator<Entry<String, ModulePropertyMap>> it = mapIterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, ModulePropertyMap> e = it.next();
|
||||
sb.append("[");
|
||||
sb.append(e.getKey());
|
||||
sb.append("|");
|
||||
sb.append(e.getValue());
|
||||
sb.append("]");
|
||||
}
|
||||
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.sudoplay.joise.module.Module;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ModulePropertyMap extends LinkedHashMap<String, Object> {
|
||||
|
||||
public ModulePropertyMap() {
|
||||
// serialization
|
||||
}
|
||||
|
||||
public ModulePropertyMap(Module module) {
|
||||
setModule(module);
|
||||
}
|
||||
|
||||
public void setModule(Module module) {
|
||||
super.put("module", module.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object put(String key, Object value) {
|
||||
if (key == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (value == null) {
|
||||
return super.put(key, null);
|
||||
} else {
|
||||
return super.put(key, value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
if (key == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
Object value = super.get(key);
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getAsString(String key) {
|
||||
return get(key).toString();
|
||||
}
|
||||
|
||||
public long getAsLong(String key) {
|
||||
try {
|
||||
return Long.parseLong(getAsString(key));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new JoiseException("Expecting property [" + key + ", "
|
||||
+ getAsString(key) + "] to be a long");
|
||||
}
|
||||
}
|
||||
|
||||
public double getAsDouble(String key) {
|
||||
try {
|
||||
return Double.parseDouble(getAsString(key));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new JoiseException("Expecting property [" + key + ", "
|
||||
+ getAsString(key) + "] to be a double");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getAsBoolean(String key) {
|
||||
String candidate = getAsString(key).toLowerCase();
|
||||
if ("true".equals(candidate) || "false".equals(candidate)) {
|
||||
return Boolean.parseBoolean(getAsString(key));
|
||||
} else {
|
||||
throw new JoiseException("Expecting property [" + key + ", "
|
||||
+ getAsString(key) + "] to be a boolean");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isModuleID(String key) {
|
||||
return getAsString(key).startsWith("func_");
|
||||
}
|
||||
|
||||
public boolean contains(String key) {
|
||||
return super.get(key) != null;
|
||||
}
|
||||
|
||||
public Iterator<Entry<String, Object>> iterator() {
|
||||
return super.entrySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Iterator<Entry<String, Object>> it = iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, Object> e = it.next();
|
||||
sb.append("[");
|
||||
sb.append(e.getKey());
|
||||
sb.append("|");
|
||||
sb.append(e.getValue());
|
||||
sb.append("]");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.generator;
|
||||
|
||||
public abstract class BasePRNG {
|
||||
|
||||
public abstract int get();
|
||||
|
||||
public abstract void setSeed(long seed);
|
||||
|
||||
public void setSeedTime() {
|
||||
setSeed(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public int getTarget(int t) {
|
||||
double v = get01();
|
||||
return (int) (v * (double) t);
|
||||
}
|
||||
|
||||
public double get01() {
|
||||
return ((double) get() / (double) 4294967295L) + 0.5;
|
||||
}
|
||||
|
||||
public int getRange(int low, int high) {
|
||||
if (high < low) {
|
||||
int temp = low;
|
||||
low = high;
|
||||
high = temp;
|
||||
}
|
||||
double range = (double) ((high - low) + 1);
|
||||
double val = (double) low + get01() * range;
|
||||
return (int) val;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.sudoplay.joise.generator
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-02-20.
|
||||
*/
|
||||
class Xorshift128plus : BasePRNG() {
|
||||
|
||||
private var s0: Long = 0
|
||||
private var s1: Long = 0
|
||||
|
||||
init {
|
||||
setSeed(10000L)
|
||||
}
|
||||
|
||||
override fun get(): Int {
|
||||
var x = s0
|
||||
val y = s1
|
||||
s0 = y
|
||||
x = x xor (x shl 23)
|
||||
s1 = x xor y xor (x ushr 17) xor (y ushr 26)
|
||||
return (s1 + y).toInt()
|
||||
}
|
||||
|
||||
override fun setSeed(seed: Long) {
|
||||
if (seed == 0L)
|
||||
throw IllegalArgumentException("Invalid seed: cannot be zero")
|
||||
|
||||
s0 = (6364136223846793005L * seed + 1442695040888963407L)
|
||||
s1 = (6364136223846793005L * s0 + 1442695040888963407L)
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public class Array2Double {
|
||||
|
||||
public static final byte X = 0;
|
||||
public static final byte Y = 1;
|
||||
|
||||
private int[] size = new int[2];
|
||||
private double[] data;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Array2Double() {}
|
||||
|
||||
public Array2Double(int x, int y) {
|
||||
this(x, y, new double[x * y]);
|
||||
}
|
||||
|
||||
public Array2Double(int x, int y, double[] data) {
|
||||
size[X] = x;
|
||||
size[Y] = y;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void set(int x, int y, double v) {
|
||||
data[x + size[X] * y] = v;
|
||||
}
|
||||
|
||||
public double get(int x, int y) {
|
||||
return data[x + size[X] * y];
|
||||
}
|
||||
|
||||
public double[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int[] getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return size[X];
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return size[Y];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public class Array2DoubleWriter implements Mapping2DWriter {
|
||||
|
||||
private Array2Double data;
|
||||
|
||||
public Array2DoubleWriter(int x, int y) {
|
||||
this(new Array2Double(x, y));
|
||||
}
|
||||
|
||||
public Array2DoubleWriter(Array2Double data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Array2Double getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int x, int y, double value) {
|
||||
data.set(x, y, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public class Array3Double {
|
||||
|
||||
public static final byte X = 0;
|
||||
public static final byte Y = 1;
|
||||
public static final byte Z = 2;
|
||||
public static final byte XY = 3;
|
||||
|
||||
private int[] size = new int[4];
|
||||
private double[] data;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Array3Double() {}
|
||||
|
||||
public Array3Double(int x, int y, int z) {
|
||||
size[X] = x;
|
||||
size[Y] = y;
|
||||
size[Z] = z;
|
||||
size[XY] = x * y;
|
||||
data = new double[x * y * z];
|
||||
}
|
||||
|
||||
public void set(int x, int y, int z, double v) {
|
||||
data[x + (size[X] * y) + (size[XY] * z)] = v;
|
||||
}
|
||||
|
||||
public double get(int x, int y, int z) {
|
||||
return data[x + (size[X] * y) + (size[XY] * z)];
|
||||
}
|
||||
|
||||
public double[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int[] getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return size[X];
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return size[Y];
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return size[Z];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public class Array3DoubleWriter implements Mapping3DWriter {
|
||||
|
||||
private Array3Double data;
|
||||
|
||||
public Array3DoubleWriter(int x, int y, int z) {
|
||||
this(new Array3Double(x, y, z));
|
||||
}
|
||||
|
||||
public Array3DoubleWriter(Array3Double data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Array3Double getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int x, int y, int z, double value) {
|
||||
data.set(x, y, z, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,753 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
import com.sudoplay.joise.module.Module;
|
||||
|
||||
public final class Mapping {
|
||||
|
||||
private static final double TWO_PI = Math.PI * 2.0;
|
||||
|
||||
private Mapping() {
|
||||
// do not instantiate
|
||||
}
|
||||
|
||||
public static void map2D(MappingMode mode, int width, int height, Module m,
|
||||
MappingRange range, Mapping2DWriter writer,
|
||||
MappingUpdateListener listener, double z) {
|
||||
|
||||
if (writer == null) {
|
||||
writer = Mapping2DWriter.NULL_WRITER;
|
||||
}
|
||||
|
||||
if (listener == null) {
|
||||
listener = MappingUpdateListener.NULL_LISTENER;
|
||||
}
|
||||
|
||||
double p, q;
|
||||
double nx, ny, nz, nw, nu, nv;
|
||||
double r;
|
||||
double zval;
|
||||
|
||||
double dx, dy, dz;
|
||||
double dx_div_2pi;
|
||||
double dy_div_2pi;
|
||||
double dz_div_2pi;
|
||||
|
||||
double iw = 1.0 / (double) width;
|
||||
double ih = 1.0 / (double) height;
|
||||
|
||||
double total = width * height;
|
||||
double current = 0;
|
||||
|
||||
switch (mode) {
|
||||
|
||||
case NORMAL:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.map0.y + q * dy;
|
||||
nz = z;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_X:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.map0.y + q * dy;
|
||||
nw = z;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_Y:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nw = z;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_Z:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
r = (z - range.map0.z) / (range.map1.z - range.map0.z);
|
||||
zval = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.map0.y + p * dx;
|
||||
|
||||
nz = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
|
||||
nw = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_XY:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nu = z;
|
||||
nv = 0;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_XZ:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
r = (z - range.map0.z) / (range.map1.z - range.map0.z);
|
||||
zval = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dz;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.map0.y + q * dy;
|
||||
nw = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
|
||||
nu = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
|
||||
nv = 0;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_YZ:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
r = (z - range.map0.z) / (range.map1.z - range.map0.z);
|
||||
zval = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
|
||||
nu = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
|
||||
nv = 0;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_XYZ:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
r = (z - range.map0.z) / (range.map1.z - range.map0.z);
|
||||
zval = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nu = range.loop0.z + Math.cos(zval * TWO_PI) * dz_div_2pi;
|
||||
nv = range.loop0.z + Math.sin(zval * TWO_PI) * dz_div_2pi;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void map2DNoZ(MappingMode mode, int width, int height,
|
||||
Module m, MappingRange range, Mapping2DWriter writer,
|
||||
MappingUpdateListener listener) {
|
||||
|
||||
if (writer == null) {
|
||||
writer = Mapping2DWriter.NULL_WRITER;
|
||||
}
|
||||
|
||||
if (listener == null) {
|
||||
listener = MappingUpdateListener.NULL_LISTENER;
|
||||
}
|
||||
|
||||
double p, q;
|
||||
double nx, ny, nz, nw;
|
||||
|
||||
double dx, dy;
|
||||
double dx_div_2pi;
|
||||
double dy_div_2pi;
|
||||
|
||||
double iw = 1.0 / (double) width;
|
||||
double ih = 1.0 / (double) height;
|
||||
|
||||
double total = width * height;
|
||||
double current = 0;
|
||||
|
||||
switch (mode) {
|
||||
|
||||
case NORMAL:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.map0.y + q * dy;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_X:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.map0.y + q * dy;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_Y:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_XY:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
|
||||
writer.write(x, y, m.get(nx, ny, nz, nw));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_Z:
|
||||
case SEAMLESS_XZ:
|
||||
case SEAMLESS_YZ:
|
||||
case SEAMLESS_XYZ:
|
||||
throw new UnsupportedOperationException(mode.toString());
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void map3D(MappingMode mode, int width, int height, int depth,
|
||||
Module m, MappingRange range, Mapping3DWriter writer,
|
||||
MappingUpdateListener listener) {
|
||||
|
||||
if (writer == null) {
|
||||
writer = Mapping3DWriter.NULL_WRITER;
|
||||
}
|
||||
|
||||
if (listener == null) {
|
||||
listener = MappingUpdateListener.NULL_LISTENER;
|
||||
}
|
||||
|
||||
double p, q, r;
|
||||
double nx, ny, nz, nw, nu, nv;
|
||||
|
||||
double dx, dy, dz;
|
||||
double dx_div_2pi;
|
||||
double dy_div_2pi;
|
||||
double dz_div_2pi;
|
||||
|
||||
double iw = 1.0 / (double) width;
|
||||
double ih = 1.0 / (double) height;
|
||||
double id = 1.0 / (double) depth;
|
||||
|
||||
double total = width * height * depth;
|
||||
double current = 0;
|
||||
|
||||
switch (mode) {
|
||||
|
||||
case NORMAL:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
dz = range.map1.z - range.map0.z;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.map0.y + q * dy;
|
||||
nz = range.map0.z + r * dz;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_X:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
dz = range.map1.z - range.map0.z;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.map0.y + q * dy;
|
||||
nw = range.map0.z + r * dz;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz, nw));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_Y:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
dz = range.map1.z - range.map0.z;
|
||||
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.map0.z + r * dz;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz, nw));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_Z:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
r = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.map0.y + q * dy;
|
||||
nz = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
|
||||
nw = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz, nw));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_XY:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
dz = range.map1.z - range.map0.z;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nu = range.map0.z + r * dz;
|
||||
nv = 0;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_XZ:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.map1.y - range.map0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
r = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.map0.y + q * dy;
|
||||
nw = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
|
||||
nu = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
|
||||
nv = 0;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_YZ:
|
||||
|
||||
dx = range.map1.x - range.map0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
r = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
nx = range.map0.x + p * dx;
|
||||
ny = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nz = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
|
||||
nu = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
|
||||
nv = 0;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
case SEAMLESS_XYZ:
|
||||
|
||||
dx = range.loop1.x - range.loop0.x;
|
||||
dy = range.loop1.y - range.loop0.y;
|
||||
dz = range.loop1.z - range.loop0.z;
|
||||
|
||||
dx_div_2pi = dx / TWO_PI;
|
||||
dy_div_2pi = dy / TWO_PI;
|
||||
dz_div_2pi = dz / TWO_PI;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < depth; z++) {
|
||||
|
||||
p = (double) x * iw;
|
||||
q = (double) y * ih;
|
||||
r = (double) z * id;
|
||||
|
||||
p = p * (range.map1.x - range.map0.x) / dx;
|
||||
q = q * (range.map1.y - range.map0.y) / dy;
|
||||
r = r * (range.map1.z - range.map0.z) / dz;
|
||||
|
||||
nx = range.loop0.x + Math.cos(p * TWO_PI) * dx_div_2pi;
|
||||
ny = range.loop0.x + Math.sin(p * TWO_PI) * dx_div_2pi;
|
||||
nz = range.loop0.y + Math.cos(q * TWO_PI) * dy_div_2pi;
|
||||
nw = range.loop0.y + Math.sin(q * TWO_PI) * dy_div_2pi;
|
||||
nu = range.loop0.z + Math.cos(r * TWO_PI) * dz_div_2pi;
|
||||
nv = range.loop0.z + Math.sin(r * TWO_PI) * dz_div_2pi;
|
||||
|
||||
writer.write(x, y, z, m.get(nx, ny, nz, nw, nu, nv));
|
||||
listener.update(++current, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public interface Mapping2DWriter {
|
||||
|
||||
public void write(int x, int y, double value);
|
||||
|
||||
public static final Mapping2DWriter NULL_WRITER = new Mapping2DWriter() {
|
||||
@Override
|
||||
public void write(int x, int y, double value) {
|
||||
// do nothing
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public interface Mapping3DWriter {
|
||||
|
||||
public void write(int x, int y, int z, double value);
|
||||
|
||||
public static final Mapping3DWriter NULL_WRITER = new Mapping3DWriter() {
|
||||
@Override
|
||||
public void write(int x, int y, int z, double value) {
|
||||
// do nothing
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public enum MappingMode {
|
||||
NORMAL, SEAMLESS_X, SEAMLESS_Y, SEAMLESS_Z, SEAMLESS_XY, SEAMLESS_XZ, SEAMLESS_YZ, SEAMLESS_XYZ
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
import com.sudoplay.joise.noise.Util.Vector3d;
|
||||
|
||||
public class MappingRange {
|
||||
public Vector3d map0 = new Vector3d(-1, -1, -1);
|
||||
public Vector3d map1 = new Vector3d(1, 1, 1);
|
||||
public Vector3d loop0 = new Vector3d(-1, -1, -1);
|
||||
public Vector3d loop1 = new Vector3d(1, 1, 1);
|
||||
|
||||
public static final MappingRange DEFAULT = new MappingRange();
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.mapping;
|
||||
|
||||
public interface MappingUpdateListener {
|
||||
|
||||
public void update(double current, double total);
|
||||
|
||||
public static final MappingUpdateListener NULL_LISTENER = new MappingUpdateListener() {
|
||||
@Override
|
||||
public void update(double current, double total) {
|
||||
// do nothing
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,371 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.sudoplay.joise.JoiseException;
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public abstract class Module {
|
||||
|
||||
public static final long DEFAULT_SEED = 10000;
|
||||
public static final int MAX_SOURCES = 10;
|
||||
|
||||
protected double spacing = 0.0001;
|
||||
|
||||
public abstract double get(double x, double y);
|
||||
|
||||
public abstract double get(double x, double y, double z);
|
||||
|
||||
public abstract double get(double x, double y, double z, double w);
|
||||
|
||||
public abstract double get(double x, double y, double z, double w, double u,
|
||||
double v);
|
||||
|
||||
protected static AtomicInteger nextId = new AtomicInteger();
|
||||
|
||||
private String id = setId();
|
||||
|
||||
protected String setId() {
|
||||
return "func_" + nextId.incrementAndGet();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ModuleMap getModuleMap() {
|
||||
ModuleMap map = new ModuleMap();
|
||||
_writeToMap(map);
|
||||
return map;
|
||||
}
|
||||
|
||||
public void writeToMap(ModuleMap map) {
|
||||
if (map.contains(id)) {
|
||||
return;
|
||||
}
|
||||
_writeToMap(map);
|
||||
}
|
||||
|
||||
protected abstract void _writeToMap(ModuleMap map);
|
||||
|
||||
public abstract Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map);
|
||||
|
||||
public void setDerivativeSpacing(double spacing) {
|
||||
this.spacing = spacing;
|
||||
}
|
||||
|
||||
public double getDX(double x, double y) {
|
||||
return (get(x - spacing, y) - get(x + spacing, y)) / spacing;
|
||||
}
|
||||
|
||||
public double getDY(double x, double y) {
|
||||
return (get(x, y - spacing) - get(x, y + spacing)) / spacing;
|
||||
}
|
||||
|
||||
public double getDX(double x, double y, double z) {
|
||||
return (get(x - spacing, y, z) - get(x + spacing, y, z)) / spacing;
|
||||
}
|
||||
|
||||
public double getDY(double x, double y, double z) {
|
||||
return (get(x, y - spacing, z) - get(x, y + spacing, z)) / spacing;
|
||||
}
|
||||
|
||||
public double getDZ(double x, double y, double z) {
|
||||
return (get(x, y, z - spacing) - get(x, y, z + spacing)) / spacing;
|
||||
}
|
||||
|
||||
public double getDX(double x, double y, double z, double w) {
|
||||
return (get(x - spacing, y, z, w) - get(x + spacing, y, z, w)) / spacing;
|
||||
}
|
||||
|
||||
public double getDY(double x, double y, double z, double w) {
|
||||
return (get(x, y - spacing, z, w) - get(x, y + spacing, z, w)) / spacing;
|
||||
}
|
||||
|
||||
public double getDZ(double x, double y, double z, double w) {
|
||||
return (get(x, y, z - spacing, w) - get(x, y, z + spacing, w)) / spacing;
|
||||
}
|
||||
|
||||
public double getDW(double x, double y, double z, double w) {
|
||||
return (get(x, y, z, w - spacing) - get(x, y, z, w + spacing)) / spacing;
|
||||
}
|
||||
|
||||
public double getDX(double x, double y, double z, double w, double u, double v) {
|
||||
return (get(x - spacing, y, z, w, u, v) - get(x + spacing, y, z, w, u, v))
|
||||
/ spacing;
|
||||
}
|
||||
|
||||
public double getDY(double x, double y, double z, double w, double u, double v) {
|
||||
return (get(x, y - spacing, z, w, u, v) - get(x, y + spacing, z, w, u, v))
|
||||
/ spacing;
|
||||
}
|
||||
|
||||
public double getDZ(double x, double y, double z, double w, double u, double v) {
|
||||
return (get(x, y, z - spacing, w, u, v) - get(x, y, z + spacing, w, u, v))
|
||||
/ spacing;
|
||||
}
|
||||
|
||||
public double getDW(double x, double y, double z, double w, double u, double v) {
|
||||
return (get(x, y, z, w - spacing, u, v) - get(x, y, z, w + spacing, u, v))
|
||||
/ spacing;
|
||||
}
|
||||
|
||||
public double getDU(double x, double y, double z, double w, double u, double v) {
|
||||
return (get(x, y, z, w, u - spacing, v) - get(x, y, z, w, u + spacing, v))
|
||||
/ spacing;
|
||||
}
|
||||
|
||||
public double getDV(double x, double y, double z, double w, double u, double v) {
|
||||
return (get(x, y, z, w, u, v - spacing) - get(x, y, z, w, u, v + spacing))
|
||||
/ spacing;
|
||||
}
|
||||
|
||||
protected void assertMaxSources(int index) {
|
||||
if (index < 0 || index >= MAX_SOURCES) {
|
||||
throw new IllegalArgumentException("expecting index < " + MAX_SOURCES
|
||||
+ " but was " + index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a scalar property from the provided property map and set the property
|
||||
* in this module using reflection to call the supplied method name with the
|
||||
* retrieved property passed as an argument. If the scalar is a module name,
|
||||
* the module is retrieved from the provided {@link ModuleInstanceMap} and set
|
||||
* using the reflected method provided.
|
||||
*
|
||||
* @param name
|
||||
* @param methodName
|
||||
* @param props
|
||||
* @param map
|
||||
*
|
||||
* @throws JoiseException
|
||||
* if there is an error with the retrieval or setting of the
|
||||
* property
|
||||
*/
|
||||
protected void readScalar(String name, String methodName,
|
||||
ModulePropertyMap props, ModuleInstanceMap map) {
|
||||
|
||||
try {
|
||||
if (props.isModuleID(name)) {
|
||||
Method method = getClass().getMethod(methodName, Module.class);
|
||||
method.invoke(this, new Object[] { map.get(props.get(name)) });
|
||||
} else {
|
||||
Method method = getClass().getMethod(methodName, double.class);
|
||||
method.invoke(this, new Object[] { props.getAsDouble(name) });
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new JoiseException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a scalar property to the provided property map. If the scalar is a
|
||||
* module, {@link #_writeToMap(ModuleMap)} is called on the scalar's module.
|
||||
*
|
||||
* @param key
|
||||
* @param scalar
|
||||
* @param props
|
||||
* @param map
|
||||
*/
|
||||
protected void writeScalar(String key, ScalarParameter scalar,
|
||||
ModulePropertyMap props, ModuleMap map) {
|
||||
|
||||
props.put(key, scalar);
|
||||
if (scalar != null && scalar.isModule()) {
|
||||
scalar.getModule()._writeToMap(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an enum property from the provided property map and set the property
|
||||
* in this module using reflection to call the supplied method name with the
|
||||
* retrieved property passed as an argument.
|
||||
*
|
||||
* @param name
|
||||
* @param methodName
|
||||
* @param c
|
||||
* @param props
|
||||
*/
|
||||
protected <T extends Enum<T>> void readEnum(String name, String methodName,
|
||||
Class<T> c, ModulePropertyMap props) {
|
||||
|
||||
try {
|
||||
Method method = getClass().getMethod(methodName, c);
|
||||
T _enum = Enum.valueOf(c, props.get(name).toString().toUpperCase());
|
||||
method.invoke(this, new Object[] { _enum });
|
||||
} catch (Exception e) {
|
||||
throw new JoiseException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an enum property to the provided property map. The enum is converted
|
||||
* to lower-case.
|
||||
*
|
||||
* @param key
|
||||
* @param _enum
|
||||
* @param props
|
||||
*/
|
||||
protected void writeEnum(String key, Enum<?> _enum, ModulePropertyMap props) {
|
||||
|
||||
props.put(key, _enum.toString().toLowerCase());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a long property from the provided property map and set the property in
|
||||
* this module using reflection to call the supplied method name with the
|
||||
* retrieved property passed as an argument.
|
||||
*
|
||||
* @param key
|
||||
* @param methodName
|
||||
* @param props
|
||||
*/
|
||||
protected void readLong(String key, String methodName, ModulePropertyMap props) {
|
||||
|
||||
try {
|
||||
Method method = getClass().getMethod(methodName, long.class);
|
||||
method.invoke(this, new Object[] { props.getAsLong(key) });
|
||||
} catch (Exception e) {
|
||||
throw new JoiseException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a long property to the provided property map.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param props
|
||||
*/
|
||||
protected void writeLong(String key, long value, ModulePropertyMap props) {
|
||||
|
||||
props.put(key, value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a double property from the provided property map and set the property
|
||||
* in this module using reflection to call the supplied method name with the
|
||||
* retrieved property passed as an argument.
|
||||
*
|
||||
* @param key
|
||||
* @param methodName
|
||||
* @param props
|
||||
*/
|
||||
protected void readDouble(String key, String methodName,
|
||||
ModulePropertyMap props) {
|
||||
|
||||
try {
|
||||
Method method = getClass().getMethod(methodName, double.class);
|
||||
method.invoke(this, new Object[] { props.getAsDouble(key) });
|
||||
} catch (Exception e) {
|
||||
throw new JoiseException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a double property to the provided property map.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param props
|
||||
*/
|
||||
protected void writeDouble(String key, double value, ModulePropertyMap props) {
|
||||
|
||||
props.put(key, value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a boolean property from the provided property map and set the property
|
||||
* in this module using reflection to call the supplied method name with the
|
||||
* retrieved property passed as an argument.
|
||||
*
|
||||
* @param key
|
||||
* @param methodName
|
||||
* @param props
|
||||
*/
|
||||
protected void readBoolean(String key, String methodName,
|
||||
ModulePropertyMap props) {
|
||||
|
||||
try {
|
||||
Method method = getClass().getMethod(methodName, boolean.class);
|
||||
method.invoke(this, new Object[] { props.getAsBoolean(key) });
|
||||
} catch (Exception e) {
|
||||
throw new JoiseException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a boolean property to the provided property map.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param props
|
||||
*/
|
||||
protected void writeBoolean(String key, boolean value, ModulePropertyMap props) {
|
||||
|
||||
props.put(key, String.valueOf(value));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleAbs extends SourcedModule {
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return Math.abs(source.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return Math.abs(source.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return Math.abs(source.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return Math.abs(source.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,305 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import static com.sudoplay.joise.noise.Util.clamp;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.generator.Xorshift128plus;
|
||||
import com.sudoplay.util.Checked;
|
||||
|
||||
public class ModuleAutoCorrect extends SourcedModule {
|
||||
|
||||
public static final double DEFAULT_LOW = 0.0;
|
||||
public static final double DEFAULT_HIGH = 1.0;
|
||||
public static final int DEFAULT_SAMPLES = 100;
|
||||
public static final double DEFAULT_SAMPLE_SCALE = 1.0;
|
||||
|
||||
protected double low;
|
||||
protected double high;
|
||||
|
||||
protected double sampleScale = DEFAULT_SAMPLE_SCALE;
|
||||
|
||||
protected double scale2, offset2;
|
||||
protected double scale3, offset3;
|
||||
protected double scale4, offset4;
|
||||
protected double scale6, offset6;
|
||||
|
||||
protected boolean locked;
|
||||
|
||||
protected int samples = DEFAULT_SAMPLES;
|
||||
|
||||
public ModuleAutoCorrect() {
|
||||
this(DEFAULT_LOW, DEFAULT_HIGH);
|
||||
}
|
||||
|
||||
public ModuleAutoCorrect(double low, double high) {
|
||||
this.low = low;
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public void setRange(double low, double high) {
|
||||
this.low = low;
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public void setLow(double low) {
|
||||
this.low = low;
|
||||
}
|
||||
|
||||
public void setHigh(double high) {
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public void setSamples(long s) {
|
||||
samples = Checked.safeLongToInt(s);
|
||||
}
|
||||
|
||||
public void setSampleScale(double s) {
|
||||
sampleScale = s;
|
||||
}
|
||||
|
||||
public void setLocked(boolean lock) {
|
||||
locked = lock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSource(double source) {
|
||||
super.setSource(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSource(Module source) {
|
||||
super.setSource(source);
|
||||
}
|
||||
|
||||
public void calculate() {
|
||||
if (!source.isModule() || locked) return;
|
||||
|
||||
double mn, mx;
|
||||
Xorshift128plus lcg = new Xorshift128plus();
|
||||
|
||||
// Calculate 2D
|
||||
mn = 10000.0;
|
||||
mx = -10000.0;
|
||||
for (int c = 0; c < samples; c++) {
|
||||
double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
|
||||
double v = source.get(nx, ny);
|
||||
if (v < mn) mn = v;
|
||||
if (v > mx) mx = v;
|
||||
}
|
||||
scale2 = (high - low) / (mx - mn);
|
||||
offset2 = low - mn * scale2;
|
||||
|
||||
// Calculate 3D
|
||||
mn = 10000.0;
|
||||
mx = -10000.0;
|
||||
for (int c = 0; c < samples; c++) {
|
||||
double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
|
||||
double v = source.get(nx, ny, nz);
|
||||
if (v < mn) mn = v;
|
||||
if (v > mx) mx = v;
|
||||
}
|
||||
scale3 = (high - low) / (mx - mn);
|
||||
offset3 = low - mn * scale3;
|
||||
|
||||
// Calculate 4D
|
||||
mn = 10000.0;
|
||||
mx = -10000.0;
|
||||
for (int c = 0; c < samples; c++) {
|
||||
double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double nw = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
|
||||
double v = source.get(nx, ny, nz, nw);
|
||||
if (v < mn) mn = v;
|
||||
if (v > mx) mx = v;
|
||||
}
|
||||
scale4 = (high - low) / (mx - mn);
|
||||
offset4 = low - mn * scale4;
|
||||
|
||||
// Calculate 6D
|
||||
mn = 10000.0;
|
||||
mx = -10000.0;
|
||||
for (int c = 0; c < samples; c++) {
|
||||
double nx = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double ny = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double nz = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double nw = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double nu = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
double nv = (lcg.get01() * 4.0 - 2.0) * sampleScale;
|
||||
|
||||
double v = source.get(nx, ny, nz, nw, nu, nv);
|
||||
if (v < mn) mn = v;
|
||||
if (v > mx) mx = v;
|
||||
}
|
||||
scale6 = (high - low) / (mx - mn);
|
||||
offset6 = low - mn * scale6;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double v = source.get(x, y);
|
||||
return clamp(v * scale2 + offset2, low, high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double v = source.get(x, y, z);
|
||||
return clamp(v * scale3 + offset3, low, high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double v = source.get(x, y, z, w);
|
||||
return clamp(v * scale4 + offset4, low, high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double val = source.get(x, y, z, w, u, v);
|
||||
return clamp(val * scale6 + offset6, low, high);
|
||||
}
|
||||
|
||||
public double getOffset2D() {
|
||||
return offset2;
|
||||
}
|
||||
|
||||
public double getOffset3D() {
|
||||
return offset3;
|
||||
}
|
||||
|
||||
public double getOffset4D() {
|
||||
return offset4;
|
||||
}
|
||||
|
||||
public double getOffset6D() {
|
||||
return offset6;
|
||||
}
|
||||
|
||||
public double getScale2D() {
|
||||
return scale2;
|
||||
}
|
||||
|
||||
public double getScale3D() {
|
||||
return scale3;
|
||||
}
|
||||
|
||||
public double getScale4D() {
|
||||
return scale4;
|
||||
}
|
||||
|
||||
public double getScale6D() {
|
||||
return scale6;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeDouble("low", low, props);
|
||||
writeDouble("high", high, props);
|
||||
writeLong("samples", samples, props);
|
||||
writeDouble("sampleScale", sampleScale, props);
|
||||
writeBoolean("locked", locked, props);
|
||||
|
||||
if (locked) {
|
||||
writeDouble("scale2", scale2, props);
|
||||
writeDouble("offset2", offset2, props);
|
||||
writeDouble("scale3", scale3, props);
|
||||
writeDouble("offset3", offset3, props);
|
||||
writeDouble("scale4", scale4, props);
|
||||
writeDouble("offset4", offset4, props);
|
||||
writeDouble("scale6", scale6, props);
|
||||
writeDouble("offset6", offset6, props);
|
||||
}
|
||||
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readDouble("low", "setLow", props);
|
||||
readDouble("high", "setHigh", props);
|
||||
readLong("samples", "setSamples", props);
|
||||
readDouble("sampleScale", "setSampleScale", props);
|
||||
readBoolean("locked", "setLocked", props);
|
||||
|
||||
if (locked) {
|
||||
scale2 = props.getAsDouble("scale2");
|
||||
offset2 = props.getAsDouble("offset2");
|
||||
scale3 = props.getAsDouble("scale3");
|
||||
offset3 = props.getAsDouble("offset3");
|
||||
scale4 = props.getAsDouble("scale4");
|
||||
offset4 = props.getAsDouble("offset4");
|
||||
scale6 = props.getAsDouble("scale6");
|
||||
offset6 = props.getAsDouble("offset6");
|
||||
}
|
||||
|
||||
readSource(props, map);
|
||||
calculate();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.generator.Xorshift128plus;
|
||||
import com.sudoplay.joise.noise.Interpolator;
|
||||
import com.sudoplay.joise.noise.Noise;
|
||||
|
||||
public class ModuleBasisFunction extends SeedableModule {
|
||||
|
||||
public enum BasisType {
|
||||
VALUE, GRADIENT, GRADVAL, SIMPLEX, WHITE
|
||||
}
|
||||
|
||||
public enum InterpolationType {
|
||||
NONE, LINEAR, CUBIC, QUINTIC
|
||||
}
|
||||
|
||||
protected double[] scale = new double[4];
|
||||
protected double[] offset = new double[4];
|
||||
protected double[][] rotMatrix = new double[3][3];
|
||||
protected double cos2d, sin2d;
|
||||
|
||||
protected Noise.Function2D func2D;
|
||||
protected Noise.Function3D func3D;
|
||||
protected Noise.Function4D func4D;
|
||||
protected Noise.Function6D func6D;
|
||||
|
||||
protected Interpolator interpolator;
|
||||
|
||||
protected BasisType basisType;
|
||||
protected InterpolationType interpolationType;
|
||||
|
||||
public ModuleBasisFunction() {
|
||||
this(BasisType.GRADIENT, InterpolationType.QUINTIC, 10000);
|
||||
}
|
||||
|
||||
public ModuleBasisFunction(BasisType type) {
|
||||
this(type, InterpolationType.QUINTIC, 10000);
|
||||
}
|
||||
|
||||
public ModuleBasisFunction(BasisType type, InterpolationType interpolationType) {
|
||||
this(type, interpolationType, 10000);
|
||||
}
|
||||
|
||||
public ModuleBasisFunction(BasisType type,
|
||||
InterpolationType interpolationType, long seed) {
|
||||
setType(type);
|
||||
setInterpolation(interpolationType);
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
public void setType(BasisType type) {
|
||||
basisType = type;
|
||||
switch (type) {
|
||||
case GRADVAL:
|
||||
func2D = Noise.Function2D.GRADVAL;
|
||||
func3D = Noise.Function3D.GRADVAL;
|
||||
func4D = Noise.Function4D.GRADVAL;
|
||||
func6D = Noise.Function6D.GRADVAL;
|
||||
break;
|
||||
case SIMPLEX:
|
||||
func2D = Noise.Function2D.SIMPLEX;
|
||||
func3D = Noise.Function3D.SIMPLEX;
|
||||
func4D = Noise.Function4D.SIMPLEX;
|
||||
func6D = Noise.Function6D.SIMPLEX;
|
||||
break;
|
||||
case VALUE:
|
||||
func2D = Noise.Function2D.VALUE;
|
||||
func3D = Noise.Function3D.VALUE;
|
||||
func4D = Noise.Function4D.VALUE;
|
||||
func6D = Noise.Function6D.VALUE;
|
||||
break;
|
||||
case WHITE:
|
||||
func2D = Noise.Function2D.WHITE;
|
||||
func3D = Noise.Function3D.WHITE;
|
||||
func4D = Noise.Function4D.WHITE;
|
||||
func6D = Noise.Function6D.WHITE;
|
||||
break;
|
||||
case GRADIENT:
|
||||
// fallthrough intentional
|
||||
default:
|
||||
func2D = Noise.Function2D.GRADIENT;
|
||||
func3D = Noise.Function3D.GRADIENT;
|
||||
func4D = Noise.Function4D.GRADIENT;
|
||||
func6D = Noise.Function6D.GRADIENT;
|
||||
break;
|
||||
}
|
||||
setMagicNumbers(type);
|
||||
}
|
||||
|
||||
public BasisType getBasisType() {
|
||||
return basisType;
|
||||
}
|
||||
|
||||
public void setInterpolation(InterpolationType type) {
|
||||
interpolationType = type;
|
||||
switch (type) {
|
||||
case CUBIC:
|
||||
this.interpolator = Interpolator.HERMITE;
|
||||
break;
|
||||
case LINEAR:
|
||||
this.interpolator = Interpolator.LINEAR;
|
||||
break;
|
||||
case NONE:
|
||||
this.interpolator = Interpolator.NONE;
|
||||
break;
|
||||
default:
|
||||
this.interpolator = Interpolator.QUINTIC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public InterpolationType getInterpolationType() {
|
||||
return interpolationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rotation axis and angle to use for 3D, 4D and 6D noise.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param angle
|
||||
*/
|
||||
public void setRotationAngle(double x, double y, double z, double angle) {
|
||||
double sin = Math.sin(angle);
|
||||
double cos = Math.cos(angle);
|
||||
|
||||
rotMatrix[0][0] = 1 + (1 - cos) * (x * x - 1);
|
||||
rotMatrix[1][0] = -z * sin + (1 - cos) * x * y;
|
||||
rotMatrix[2][0] = y * sin + (1 - cos) * x * z;
|
||||
|
||||
rotMatrix[0][1] = z * sin + (1 - cos) * x * y;
|
||||
rotMatrix[1][1] = 1 + (1 - cos) * (y * y - 1);
|
||||
rotMatrix[2][1] = -x * sin + (1 - cos) * y * z;
|
||||
|
||||
rotMatrix[0][2] = -y * sin + (1 - cos) * x * z;
|
||||
rotMatrix[1][2] = x * sin + (1 - cos) * y * z;
|
||||
rotMatrix[2][2] = 1 + (1 - cos) * (z * z - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
super.setSeed(seed);
|
||||
|
||||
Xorshift128plus lcg = new Xorshift128plus();
|
||||
lcg.setSeed(seed);
|
||||
|
||||
double ax, ay, az;
|
||||
double len;
|
||||
|
||||
ax = lcg.get01();
|
||||
ay = lcg.get01();
|
||||
az = lcg.get01();
|
||||
len = Math.sqrt(ax * ax + ay * ay + az * az);
|
||||
ax /= len;
|
||||
ay /= len;
|
||||
az /= len;
|
||||
setRotationAngle(ax, ay, az, lcg.get01() * 3.141592 * 2.0);
|
||||
double angle = lcg.get01() * 3.141592 * 2.0;
|
||||
cos2d = Math.cos(angle);
|
||||
sin2d = Math.sin(angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double nx, ny;
|
||||
nx = x * cos2d - y * sin2d;
|
||||
ny = y * cos2d + x * sin2d;
|
||||
return func2D.get(nx, ny, seed, interpolator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double nx, ny, nz;
|
||||
nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z);
|
||||
ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z);
|
||||
nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z);
|
||||
return func3D.get(nx, ny, nz, seed, interpolator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double nx, ny, nz;
|
||||
nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z);
|
||||
ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z);
|
||||
nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z);
|
||||
return func4D.get(nx, ny, nz, w, seed, interpolator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double nx, ny, nz;
|
||||
nx = (rotMatrix[0][0] * x) + (rotMatrix[1][0] * y) + (rotMatrix[2][0] * z);
|
||||
ny = (rotMatrix[0][1] * x) + (rotMatrix[1][1] * y) + (rotMatrix[2][1] * z);
|
||||
nz = (rotMatrix[0][2] * x) + (rotMatrix[1][2] * y) + (rotMatrix[2][2] * z);
|
||||
return func6D.get(nx, ny, nz, w, u, v, seed, interpolator);
|
||||
}
|
||||
|
||||
protected void setMagicNumbers(BasisType type) {
|
||||
switch (type) {
|
||||
case VALUE:
|
||||
scale[0] = 1.0;
|
||||
offset[0] = 0.0;
|
||||
scale[1] = 1.0;
|
||||
offset[1] = 0.0;
|
||||
scale[2] = 1.0;
|
||||
offset[2] = 0.0;
|
||||
scale[3] = 1.0;
|
||||
offset[3] = 0.0;
|
||||
break;
|
||||
|
||||
case GRADIENT:
|
||||
scale[0] = 1.86848;
|
||||
offset[0] = -0.000118;
|
||||
scale[1] = 1.85148;
|
||||
offset[1] = -0.008272;
|
||||
scale[2] = 1.64127;
|
||||
offset[2] = -0.01527;
|
||||
scale[3] = 1.92517;
|
||||
offset[3] = 0.03393;
|
||||
break;
|
||||
|
||||
case GRADVAL:
|
||||
scale[0] = 0.6769;
|
||||
offset[0] = -0.00151;
|
||||
scale[1] = 0.6957;
|
||||
offset[1] = -0.133;
|
||||
scale[2] = 0.74622;
|
||||
offset[2] = 0.01916;
|
||||
scale[3] = 0.7961;
|
||||
offset[3] = -0.0352;
|
||||
break;
|
||||
|
||||
case WHITE:
|
||||
scale[0] = 1.0;
|
||||
offset[0] = 0.0;
|
||||
scale[1] = 1.0;
|
||||
offset[1] = 0.0;
|
||||
scale[2] = 1.0;
|
||||
offset[2] = 0.0;
|
||||
scale[3] = 1.0;
|
||||
offset[3] = 0.0;
|
||||
break;
|
||||
|
||||
default:
|
||||
scale[0] = 1.0;
|
||||
offset[0] = 0.0;
|
||||
scale[1] = 1.0;
|
||||
offset[1] = 0.0;
|
||||
scale[2] = 1.0;
|
||||
offset[2] = 0.0;
|
||||
scale[3] = 1.0;
|
||||
offset[3] = 0.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeEnum("basis", getBasisType(), props);
|
||||
writeEnum("interpolation", getInterpolationType(), props);
|
||||
writeSeed(props);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readEnum("basis", "setType", BasisType.class, props);
|
||||
readEnum("interpolation", "setInterpolation", InterpolationType.class,
|
||||
props);
|
||||
readSeed(props);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import static com.sudoplay.joise.noise.Util.bias;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleBias extends SourcedModule {
|
||||
|
||||
protected ScalarParameter bias = new ScalarParameter(0.5);
|
||||
|
||||
public ModuleBias() {}
|
||||
|
||||
public ModuleBias(double bias) {
|
||||
this.bias.set(bias);
|
||||
}
|
||||
|
||||
public ModuleBias(Module bias) {
|
||||
this.bias.set(bias);
|
||||
}
|
||||
|
||||
public void setBias(double bias) {
|
||||
this.bias.set(bias);
|
||||
}
|
||||
|
||||
public void setBias(Module bias) {
|
||||
this.bias.set(bias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double val = source.get(x, y);
|
||||
return bias(bias.get(x, y), val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double val = source.get(x, y, z);
|
||||
return bias(bias.get(x, y, z), val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double val = source.get(x, y, z, w);
|
||||
return bias(bias.get(x, y, z, w), val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double val = source.get(x, y, z, w, u, v);
|
||||
return bias(bias.get(x, y, z, w, u, v), val);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("bias", bias, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("bias", "setBias", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import static com.sudoplay.joise.noise.Util.lerp;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleBlend extends Module {
|
||||
|
||||
protected ScalarParameter low = new ScalarParameter(0.0);
|
||||
protected ScalarParameter high = new ScalarParameter(1.0);
|
||||
protected ScalarParameter control = new ScalarParameter(0.5);
|
||||
|
||||
public void setLowSource(Module source) {
|
||||
low.set(source);
|
||||
}
|
||||
|
||||
public void setLowSource(double source) {
|
||||
low.set(source);
|
||||
}
|
||||
|
||||
public void setHighSource(Module source) {
|
||||
high.set(source);
|
||||
}
|
||||
|
||||
public void setHighSource(double source) {
|
||||
high.set(source);
|
||||
}
|
||||
|
||||
public void setControlSource(Module source) {
|
||||
control.set(source);
|
||||
}
|
||||
|
||||
public void setControlSource(double source) {
|
||||
control.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double v1 = low.get(x, y);
|
||||
double v2 = high.get(x, y);
|
||||
double bl = control.get(x, y);
|
||||
bl = (bl + 1.0) * 0.5;
|
||||
return lerp(bl, v1, v2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double v1 = low.get(x, y, z);
|
||||
double v2 = high.get(x, y, z);
|
||||
double bl = control.get(x, y, z);
|
||||
return lerp(bl, v1, v2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double v1 = low.get(x, y, z, w);
|
||||
double v2 = high.get(x, y, z, w);
|
||||
double bl = control.get(x, y, z, w);
|
||||
return lerp(bl, v1, v2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double v1 = low.get(x, y, z, w, u, v);
|
||||
double v2 = high.get(x, y, z, w, u, v);
|
||||
double bl = control.get(x, y, z, w, u, v);
|
||||
return lerp(bl, v1, v2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("high", high, props, map);
|
||||
writeScalar("low", low, props, map);
|
||||
writeScalar("control", control, props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("high", "setHighSource", props, map);
|
||||
readScalar("low", "setLowSource", props, map);
|
||||
readScalar("control", "setControlSource", props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleBrightContrast extends SourcedModule {
|
||||
|
||||
protected ScalarParameter bright = new ScalarParameter(0.0);
|
||||
protected ScalarParameter threshold = new ScalarParameter(0.0);
|
||||
protected ScalarParameter factor = new ScalarParameter(1.0);
|
||||
|
||||
public void setBrightness(double b) {
|
||||
bright.set(b);
|
||||
}
|
||||
|
||||
public void setBrightness(Module source) {
|
||||
bright.set(source);
|
||||
}
|
||||
|
||||
public void setContrastThreshold(double t) {
|
||||
threshold.set(t);
|
||||
}
|
||||
|
||||
public void setContrastThreshold(Module source) {
|
||||
threshold.set(source);
|
||||
}
|
||||
|
||||
public void setContrastFactor(double f) {
|
||||
factor.set(f);
|
||||
}
|
||||
|
||||
public void setContrastFactor(Module source) {
|
||||
factor.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double val = source.get(x, y);
|
||||
// apply brightness
|
||||
val += bright.get(x, y);
|
||||
// subtract threshold, scale by factor, add threshold
|
||||
double t = threshold.get(x, y);
|
||||
val -= t;
|
||||
val *= factor.get(x, y);
|
||||
val += t;
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double val = source.get(x, y, z);
|
||||
// apply brightness
|
||||
val += bright.get(x, y, z);
|
||||
// subtract threshold, scale by factor, add threshold
|
||||
double t = threshold.get(x, y, z);
|
||||
val -= t;
|
||||
val *= factor.get(x, y, z);
|
||||
val += t;
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double val = source.get(x, y, z, w);
|
||||
// apply brightness
|
||||
val += bright.get(x, y, z, w);
|
||||
// subtract threshold, scale by factor, add threshold
|
||||
double t = threshold.get(x, y, z, w);
|
||||
val -= t;
|
||||
val *= factor.get(x, y, z, w);
|
||||
val += t;
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double val = source.get(x, y, z, w, u, v);
|
||||
// apply brightness
|
||||
val += bright.get(x, y, z, w, u, v);
|
||||
// subtract threshold, scale by factor, add threshold
|
||||
double t = threshold.get(x, y, z, w, u, v);
|
||||
val -= t;
|
||||
val *= factor.get(x, y, z, w, u, v);
|
||||
val += t;
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("brightness", bright, props, map);
|
||||
writeScalar("contrastFactor", factor, props, map);
|
||||
writeScalar("contrastThreshold", threshold, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("brightness", "setBrightness", props, map);
|
||||
readScalar("contrastFactor", "setContrastFactor", props, map);
|
||||
readScalar("contrastThreshold", "setContrastThreshold", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleCache extends SourcedModule {
|
||||
|
||||
class Cache {
|
||||
double x, y, z, w, u, v;
|
||||
double val;
|
||||
boolean valid = false;
|
||||
}
|
||||
|
||||
protected Cache c2 = new Cache();
|
||||
protected Cache c3 = new Cache();
|
||||
protected Cache c4 = new Cache();
|
||||
protected Cache c6 = new Cache();
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
if (!c2.valid || c2.x != x || c2.y != y) {
|
||||
c2.x = x;
|
||||
c2.y = y;
|
||||
c2.valid = true;
|
||||
c2.val = source.get(x, y);
|
||||
}
|
||||
return c2.val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
if (!c3.valid || c3.x != x || c3.y != y || c3.z != z) {
|
||||
c3.x = x;
|
||||
c3.y = y;
|
||||
c3.z = z;
|
||||
c3.valid = true;
|
||||
c3.val = source.get(x, y, z);
|
||||
}
|
||||
return c3.val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
if (!c4.valid || c4.x != x || c4.y != y || c4.z != z || c4.w != w) {
|
||||
c4.x = x;
|
||||
c4.y = y;
|
||||
c4.z = z;
|
||||
c4.w = w;
|
||||
c4.valid = true;
|
||||
c4.val = source.get(x, y, z, w);
|
||||
}
|
||||
return c4.val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
if (!c6.valid || c6.x != x || c6.y != y || c6.z != z || c6.w != w
|
||||
|| c6.u != u || c6.v != v) {
|
||||
c6.x = x;
|
||||
c6.y = y;
|
||||
c6.z = z;
|
||||
c6.w = w;
|
||||
c6.u = u;
|
||||
c6.v = v;
|
||||
c6.valid = true;
|
||||
c6.val = source.get(x, y, z, w, u, v);
|
||||
}
|
||||
return c6.val;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.noise.Noise;
|
||||
|
||||
public class ModuleCellGen extends SeedableModule {
|
||||
|
||||
private int id = Module.nextId.incrementAndGet();
|
||||
|
||||
public class CellularCache {
|
||||
double[] f = new double[4];
|
||||
double[] d = new double[4];
|
||||
double x, y, z, w, u, v;
|
||||
boolean valid = false;
|
||||
}
|
||||
|
||||
protected CellularCache c2 = new CellularCache();
|
||||
protected CellularCache c3 = new CellularCache();
|
||||
protected CellularCache c4 = new CellularCache();
|
||||
protected CellularCache c6 = new CellularCache();
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "func_" + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
super.setSeed(seed);
|
||||
|
||||
c2.valid = false;
|
||||
c3.valid = false;
|
||||
c4.valid = false;
|
||||
c6.valid = false;
|
||||
}
|
||||
|
||||
public CellularCache getCache(double x, double y) {
|
||||
if (!c2.valid || c2.x != x || c2.y != y) {
|
||||
Noise.cellularFunction2D(x, y, seed, c2.f, c2.d);
|
||||
c2.x = x;
|
||||
c2.y = y;
|
||||
c2.valid = true;
|
||||
}
|
||||
return c2;
|
||||
}
|
||||
|
||||
public CellularCache getCache(double x, double y, double z) {
|
||||
if (!c3.valid || c3.x != x || c3.y != y || c3.z != z) {
|
||||
Noise.cellularFunction3D(x, y, z, seed, c3.f, c3.d);
|
||||
c3.x = x;
|
||||
c3.y = y;
|
||||
c3.z = z;
|
||||
c3.valid = true;
|
||||
}
|
||||
return c3;
|
||||
}
|
||||
|
||||
public CellularCache getCache(double x, double y, double z, double w) {
|
||||
if (!c4.valid || c4.x != x || c4.y != y || c4.z != z || c4.w != w) {
|
||||
Noise.cellularFunction4D(x, y, z, w, seed, c4.f, c4.d);
|
||||
c4.x = x;
|
||||
c4.y = y;
|
||||
c4.z = z;
|
||||
c4.w = w;
|
||||
c4.valid = true;
|
||||
}
|
||||
return c4;
|
||||
}
|
||||
|
||||
public CellularCache getCache(double x, double y, double z, double w,
|
||||
double u, double v) {
|
||||
if (!c6.valid || c6.x != x || c6.y != y || c6.z != z || c6.w != w
|
||||
|| c6.u != u || c6.v != v) {
|
||||
Noise.cellularFunction6D(x, y, z, w, u, v, seed, c6.f, c6.d);
|
||||
c6.x = x;
|
||||
c6.y = y;
|
||||
c6.z = z;
|
||||
c6.w = w;
|
||||
c6.u = u;
|
||||
c6.v = v;
|
||||
c6.valid = true;
|
||||
}
|
||||
return c6;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeSeed(props);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleCellGen buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readSeed(props);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.module.ModuleCellGen.CellularCache;
|
||||
|
||||
public class ModuleCellular extends Module {
|
||||
|
||||
protected double[] coefficients = new double[4];
|
||||
protected ModuleCellGen generator;
|
||||
|
||||
public ModuleCellular() {
|
||||
setCoefficients(1, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void setCellularSource(ModuleCellGen generator) {
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
public void setCoefficients(double a, double b, double c, double d) {
|
||||
coefficients[0] = a;
|
||||
coefficients[1] = b;
|
||||
coefficients[2] = c;
|
||||
coefficients[3] = d;
|
||||
}
|
||||
|
||||
public void setCoefficient(int index, double val) {
|
||||
if (index > 3 || index < 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
coefficients[index] = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
if (generator == null) {
|
||||
return 0.0;
|
||||
}
|
||||
CellularCache c = generator.getCache(x, y);
|
||||
return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
|
||||
* coefficients[2] + c.f[3] * coefficients[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
if (generator == null) {
|
||||
return 0.0;
|
||||
}
|
||||
CellularCache c = generator.getCache(x, y, z);
|
||||
return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
|
||||
* coefficients[2] + c.f[3] * coefficients[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
if (generator == null) {
|
||||
return 0.0;
|
||||
}
|
||||
CellularCache c = generator.getCache(x, y, z, w);
|
||||
return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
|
||||
* coefficients[2] + c.f[3] * coefficients[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
if (generator == null) {
|
||||
return 0.0;
|
||||
}
|
||||
CellularCache c = generator.getCache(x, y, z, w, u, v);
|
||||
return c.f[0] * coefficients[0] + c.f[1] * coefficients[1] + c.f[2]
|
||||
* coefficients[2] + c.f[3] * coefficients[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
if (generator != null) {
|
||||
props.put("generator", generator.getId());
|
||||
generator._writeToMap(map);
|
||||
} else {
|
||||
props.put("generator", 0);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (double d : coefficients) {
|
||||
sb.append(String.valueOf(d)).append(" ");
|
||||
}
|
||||
props.put("coefficients", sb.toString().trim());
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
String coeff = props.getAsString("coefficients");
|
||||
String[] arr = coeff.split(" ");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
coefficients[i] = Double.parseDouble(arr[i]);
|
||||
}
|
||||
|
||||
String gen = props.getAsString("generator");
|
||||
setCellularSource((ModuleCellGen) map.get(gen));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import static com.sudoplay.joise.noise.Util.clamp;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleClamp extends SourcedModule {
|
||||
|
||||
protected double low;
|
||||
protected double high;
|
||||
|
||||
public ModuleClamp() {
|
||||
setRange(-1.0, 1.0);
|
||||
}
|
||||
|
||||
public ModuleClamp(double low, double high) {
|
||||
setRange(low, high);
|
||||
}
|
||||
|
||||
public void setRange(double low, double high) {
|
||||
this.low = low;
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public void setLow(double low) {
|
||||
this.low = low;
|
||||
}
|
||||
|
||||
public void setHigh(double high) {
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return clamp(source.get(x, y), low, high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return clamp(source.get(x, y, z), low, high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return clamp(source.get(x, y, z, w), low, high);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return clamp(source.get(x, y, z, w, u, v), low, high);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeDouble("low", low, props);
|
||||
writeDouble("high", high, props);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readDouble("low", "setLow", props);
|
||||
readDouble("high", "setHigh", props);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,489 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleCombiner extends Module {
|
||||
|
||||
public static enum CombinerType {
|
||||
ADD, MULT, MAX, MIN, AVG
|
||||
}
|
||||
|
||||
protected ScalarParameter[] sources = new ScalarParameter[MAX_SOURCES];
|
||||
protected CombinerType type;
|
||||
|
||||
public ModuleCombiner(CombinerType type) {
|
||||
setType(type);
|
||||
}
|
||||
|
||||
public ModuleCombiner() {
|
||||
// serialization
|
||||
}
|
||||
|
||||
public void setType(CombinerType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setSource(int index, Module source) {
|
||||
sources[index] = new ScalarParameter(source);
|
||||
}
|
||||
|
||||
public void setSource(int index, double source) {
|
||||
sources[index] = new ScalarParameter(source);
|
||||
}
|
||||
|
||||
public void clearAllSources() {
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
sources[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
switch (type) {
|
||||
case ADD:
|
||||
return addGet(x, y);
|
||||
case AVG:
|
||||
return avgGet(x, y);
|
||||
case MAX:
|
||||
return maxGet(x, y);
|
||||
case MIN:
|
||||
return minGet(x, y);
|
||||
case MULT:
|
||||
return multGet(x, y);
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
switch (type) {
|
||||
case ADD:
|
||||
return addGet(x, y, z);
|
||||
case AVG:
|
||||
return avgGet(x, y, z);
|
||||
case MAX:
|
||||
return maxGet(x, y, z);
|
||||
case MIN:
|
||||
return minGet(x, y, z);
|
||||
case MULT:
|
||||
return multGet(x, y, z);
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
switch (type) {
|
||||
case ADD:
|
||||
return addGet(x, y, z, w);
|
||||
case AVG:
|
||||
return avgGet(x, y, z, w);
|
||||
case MAX:
|
||||
return maxGet(x, y, z, w);
|
||||
case MIN:
|
||||
return minGet(x, y, z, w);
|
||||
case MULT:
|
||||
return multGet(x, y, z, w);
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
switch (type) {
|
||||
case ADD:
|
||||
return addGet(x, y, z, w, u, v);
|
||||
case AVG:
|
||||
return avgGet(x, y, z, w, u, v);
|
||||
case MAX:
|
||||
return maxGet(x, y, z, w, u, v);
|
||||
case MIN:
|
||||
return minGet(x, y, z, w, u, v);
|
||||
case MULT:
|
||||
return multGet(x, y, z, w, u, v);
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// = ADD
|
||||
// ==========================================================================
|
||||
|
||||
protected double addGet(double x, double y) {
|
||||
double value = 0.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value += sources[i].get(x, y);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected double addGet(double x, double y, double z) {
|
||||
double value = 0.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value += sources[i].get(x, y, z);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected double addGet(double x, double y, double z, double w) {
|
||||
double value = 0.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value += sources[i].get(x, y, z, w);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected double addGet(double x, double y, double z, double w, double u,
|
||||
double v) {
|
||||
double value = 0.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value += sources[i].get(x, y, z, w, u, v);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// = AVG
|
||||
// ==========================================================================
|
||||
|
||||
protected double avgGet(double x, double y) {
|
||||
int count = 0;
|
||||
double value = 0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) {
|
||||
value += sources[i].get(x, y);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0) return 0.0;
|
||||
return value / (double) count;
|
||||
}
|
||||
|
||||
protected double avgGet(double x, double y, double z) {
|
||||
int count = 0;
|
||||
double value = 0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) {
|
||||
value += sources[i].get(x, y, z);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0) return 0.0;
|
||||
return value / (double) count;
|
||||
}
|
||||
|
||||
protected double avgGet(double x, double y, double z, double w) {
|
||||
int count = 0;
|
||||
double value = 0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) {
|
||||
value += sources[i].get(x, y, z, w);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0) return 0.0;
|
||||
return value / (double) count;
|
||||
}
|
||||
|
||||
protected double avgGet(double x, double y, double z, double w, double u,
|
||||
double v) {
|
||||
int count = 0;
|
||||
double value = 0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) {
|
||||
value += sources[i].get(x, y, z, w, u, v);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0) return 0.0;
|
||||
return value / (double) count;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// = MAX
|
||||
// ==========================================================================
|
||||
|
||||
protected double maxGet(double x, double y) {
|
||||
double mx;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mx = sources[c].get(x, y);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y);
|
||||
if (val > mx) mx = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mx;
|
||||
}
|
||||
|
||||
protected double maxGet(double x, double y, double z) {
|
||||
double mx;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mx = sources[c].get(x, y, z);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y, z);
|
||||
if (val > mx) mx = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mx;
|
||||
}
|
||||
|
||||
protected double maxGet(double x, double y, double z, double w) {
|
||||
double mx;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mx = sources[c].get(x, y, z, w);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y, z, w);
|
||||
if (val > mx) mx = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mx;
|
||||
}
|
||||
|
||||
protected double maxGet(double x, double y, double z, double w, double u,
|
||||
double v) {
|
||||
double mx;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mx = sources[c].get(x, y, z, w, u, v);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y, z, w, u, v);
|
||||
if (val > mx) mx = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mx;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// = MIN
|
||||
// ==========================================================================
|
||||
|
||||
protected double minGet(double x, double y) {
|
||||
double mn;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mn = sources[c].get(x, y);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y);
|
||||
if (val < mn) mn = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mn;
|
||||
}
|
||||
|
||||
protected double minGet(double x, double y, double z) {
|
||||
double mn;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mn = sources[c].get(x, y, z);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y, z);
|
||||
if (val < mn) mn = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mn;
|
||||
}
|
||||
|
||||
protected double minGet(double x, double y, double z, double w) {
|
||||
double mn;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mn = sources[c].get(x, y, z, w);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y, z, w);
|
||||
if (val < mn) mn = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mn;
|
||||
}
|
||||
|
||||
protected double minGet(double x, double y, double z, double w, double u,
|
||||
double v) {
|
||||
double mn;
|
||||
int c = 0;
|
||||
while (c < MAX_SOURCES && sources[c] == null) {
|
||||
c++;
|
||||
}
|
||||
if (c == MAX_SOURCES) return 0.0;
|
||||
mn = sources[c].get(x, y, z, w, u, v);
|
||||
|
||||
for (int d = c; d < MAX_SOURCES; d++) {
|
||||
if (sources[d] != null) {
|
||||
double val = sources[d].get(x, y, z, w, u, v);
|
||||
if (val < mn) mn = val;
|
||||
}
|
||||
}
|
||||
|
||||
return mn;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// = MULT
|
||||
// ==========================================================================
|
||||
|
||||
protected double multGet(double x, double y) {
|
||||
double value = 1.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value *= sources[i].get(x, y);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected double multGet(double x, double y, double z) {
|
||||
double value = 1.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value *= sources[i].get(x, y, z);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected double multGet(double x, double y, double z, double w) {
|
||||
double value = 1.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value *= sources[i].get(x, y, z, w);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected double multGet(double x, double y, double z, double w, double u,
|
||||
double v) {
|
||||
double value = 1.0;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
if (sources[i] != null) value *= sources[i].get(x, y, z, w, u, v);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeEnum("type", type, props);
|
||||
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
writeScalar("source" + i, sources[i], props, map);
|
||||
}
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readEnum("type", "setType", CombinerType.class, props);
|
||||
|
||||
String name;
|
||||
Object o;
|
||||
for (int i = 0; i < MAX_SOURCES; i++) {
|
||||
o = props.get("source" + i);
|
||||
if (o != null) {
|
||||
name = o.toString();
|
||||
setSource(i, map.get(name));
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleCos extends SourcedModule {
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return Math.cos(source.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return Math.cos(source.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return Math.cos(source.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return Math.cos(source.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleFloor extends SourcedModule {
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return Math.floor(source.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return Math.floor(source.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return Math.floor(source.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return Math.floor(source.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleFunctionGradient extends SourcedModule {
|
||||
|
||||
public static final double DEFAULT_SPACING = 0.01;
|
||||
|
||||
public static enum FunctionGradientAxis {
|
||||
X_AXIS, Y_AXIS, Z_AXIS, W_AXIS, U_AXIS, V_AXIS
|
||||
}
|
||||
|
||||
protected FunctionGradientAxis axis;
|
||||
protected double spacing;
|
||||
protected double invSpacing;
|
||||
|
||||
public ModuleFunctionGradient() {
|
||||
setAxis(FunctionGradientAxis.X_AXIS);
|
||||
setSpacing(DEFAULT_SPACING);
|
||||
}
|
||||
|
||||
public void setAxis(FunctionGradientAxis axis) {
|
||||
this.axis = axis;
|
||||
}
|
||||
|
||||
public void setSpacing(double s) {
|
||||
spacing = s;
|
||||
invSpacing = 1.0 / spacing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
switch (axis) {
|
||||
case X_AXIS:
|
||||
return (source.get(x - spacing, y) - source.get(x + spacing, y))
|
||||
* invSpacing;
|
||||
case Y_AXIS:
|
||||
return (source.get(x, y - spacing) - source.get(x, y + spacing))
|
||||
* invSpacing;
|
||||
case Z_AXIS:
|
||||
return 0.0;
|
||||
case W_AXIS:
|
||||
return 0.0;
|
||||
case U_AXIS:
|
||||
return 0.0;
|
||||
case V_AXIS:
|
||||
return 0.0;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
switch (axis) {
|
||||
case X_AXIS:
|
||||
return (source.get(x - spacing, y, z) - source.get(x + spacing, y, z))
|
||||
* invSpacing;
|
||||
case Y_AXIS:
|
||||
return (source.get(x, y - spacing, z) - source.get(x, y + spacing, z))
|
||||
* invSpacing;
|
||||
case Z_AXIS:
|
||||
return (source.get(x, y, z - spacing) - source.get(x, y, z + spacing))
|
||||
* invSpacing;
|
||||
case W_AXIS:
|
||||
return 0.0;
|
||||
case U_AXIS:
|
||||
return 0.0;
|
||||
case V_AXIS:
|
||||
return 0.0;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
switch (axis) {
|
||||
case X_AXIS:
|
||||
return (source.get(x - spacing, y, z, w) - source.get(x + spacing, y, z,
|
||||
w)) * invSpacing;
|
||||
|
||||
case Y_AXIS:
|
||||
return (source.get(x, y - spacing, z, w) - source.get(x, y + spacing, z,
|
||||
w)) * invSpacing;
|
||||
|
||||
case Z_AXIS:
|
||||
return (source.get(x, y, z - spacing, w) - source.get(x, y, z + spacing,
|
||||
w)) * invSpacing;
|
||||
|
||||
case W_AXIS:
|
||||
return (source.get(x, y, z, w - spacing) - source.get(x, y, z, w
|
||||
+ spacing))
|
||||
* invSpacing;
|
||||
case U_AXIS:
|
||||
return 0.0;
|
||||
case V_AXIS:
|
||||
return 0.0;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
switch (axis) {
|
||||
case X_AXIS:
|
||||
return (source.get(x - spacing, y, z, w, u, v) - source.get(x + spacing,
|
||||
y, z, w, u, v)) * invSpacing;
|
||||
|
||||
case Y_AXIS:
|
||||
return (source.get(x, y - spacing, z, w, u, v) - source.get(x, y
|
||||
+ spacing, z, w, u, v))
|
||||
* invSpacing;
|
||||
case Z_AXIS:
|
||||
return (source.get(x, y, z - spacing, w, u, v) - source.get(x, y, z
|
||||
+ spacing, w, u, v))
|
||||
* invSpacing;
|
||||
case W_AXIS:
|
||||
return (source.get(x, y, z, w - spacing, u, v) - source.get(x, y, z, w
|
||||
+ spacing, u, v))
|
||||
* invSpacing;
|
||||
case U_AXIS:
|
||||
return (source.get(x, y, z, w, u - spacing, v) - source.get(x, y, z, w, u
|
||||
+ spacing, v))
|
||||
* invSpacing;
|
||||
case V_AXIS:
|
||||
return (source.get(x, y, z, w, u, v - spacing) - source.get(x, y, z, w,
|
||||
u, v + spacing)) * invSpacing;
|
||||
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeEnum("axis", axis, props);
|
||||
writeDouble("spacing", spacing, props);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readEnum("axis", "setAxis", FunctionGradientAxis.class, props);
|
||||
readDouble("spacing", "setSpacing", props);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.noise.Util;
|
||||
|
||||
public class ModuleGain extends SourcedModule {
|
||||
|
||||
public static final double DEFAULT_GAIN = 0.5;
|
||||
|
||||
protected ScalarParameter gain = new ScalarParameter(DEFAULT_GAIN);
|
||||
|
||||
public ModuleGain() {
|
||||
setGain(DEFAULT_GAIN);
|
||||
}
|
||||
|
||||
public ModuleGain(double gain) {
|
||||
setGain(gain);
|
||||
}
|
||||
|
||||
public void setGain(double gain) {
|
||||
this.gain.set(gain);
|
||||
}
|
||||
|
||||
public void setGain(Module gain) {
|
||||
this.gain.set(gain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return Util.gain(gain.get(x, y), source.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return Util.gain(gain.get(x, y, z), source.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return Util.gain(gain.get(x, y, z, w), source.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return Util.gain(gain.get(x, y, z, w, u, v), source.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("gain", gain, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("gain", "setGain", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleGradient extends Module {
|
||||
|
||||
public static final double DEFAULT_X1 = 0.0;
|
||||
public static final double DEFAULT_X2 = 1.0;
|
||||
public static final double DEFAULT_Y1 = 0.0;
|
||||
public static final double DEFAULT_Y2 = 1.0;
|
||||
public static final double DEFAULT_Z1 = 0.0;
|
||||
public static final double DEFAULT_Z2 = 0.0;
|
||||
public static final double DEFAULT_W1 = 0.0;
|
||||
public static final double DEFAULT_W2 = 0.0;
|
||||
public static final double DEFAULT_U1 = 0.0;
|
||||
public static final double DEFAULT_U2 = 0.0;
|
||||
public static final double DEFAULT_V1 = 0.0;
|
||||
public static final double DEFAULT_V2 = 0.0;
|
||||
|
||||
protected double gx1, gx2, gy1, gy2, gz1, gz2, gw1, gw2, gu1, gu2, gv1, gv2;
|
||||
protected double x, y, z, w, u, v;
|
||||
protected double vlen;
|
||||
|
||||
public ModuleGradient() {
|
||||
setGradient(DEFAULT_X1, DEFAULT_X2, DEFAULT_Y1, DEFAULT_Y2, DEFAULT_Z1,
|
||||
DEFAULT_Z2, DEFAULT_W1, DEFAULT_W2, DEFAULT_U1, DEFAULT_U2, DEFAULT_V1,
|
||||
DEFAULT_V2);
|
||||
}
|
||||
|
||||
public void setGradient(double x1, double x2, double y1, double y2) {
|
||||
setGradient(x1, x2, y1, y2, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void setGradient(double x1, double x2, double y1, double y2,
|
||||
double z1, double z2) {
|
||||
setGradient(x1, x2, y1, y2, z1, z2, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void setGradient(double x1, double x2, double y1, double y2,
|
||||
double z1, double z2, double w1, double w2) {
|
||||
setGradient(x1, x2, y1, y2, z1, z2, w1, w2, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void setGradient(double x1, double x2, double y1, double y2,
|
||||
double z1, double z2, double w1, double w2, double u1, double u2,
|
||||
double v1, double v2) {
|
||||
gx1 = x1;
|
||||
gx2 = x2;
|
||||
gy1 = y1;
|
||||
gy2 = y2;
|
||||
gz1 = z1;
|
||||
gz2 = z2;
|
||||
gw1 = w1;
|
||||
gw2 = w2;
|
||||
gu1 = u1;
|
||||
gu2 = u2;
|
||||
gv1 = v1;
|
||||
gv2 = v2;
|
||||
|
||||
x = x2 - x1;
|
||||
y = y2 - y1;
|
||||
z = z2 - z1;
|
||||
w = w2 - w1;
|
||||
u = u2 - u1;
|
||||
v = v2 - v1;
|
||||
|
||||
vlen = (x * x + y * y + z * z + w * w + u * u + v * v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double dx = x - gx1;
|
||||
double dy = y - gy1;
|
||||
double dp = dx * this.x + dy * this.y;
|
||||
dp /= vlen;
|
||||
return dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double dx = x - gx1;
|
||||
double dy = y - gy1;
|
||||
double dz = z - gz1;
|
||||
double dp = dx * this.x + dy * this.y + dz * this.z;
|
||||
dp /= vlen;
|
||||
return dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double dx = x - gx1;
|
||||
double dy = y - gy1;
|
||||
double dz = z - gz1;
|
||||
double dw = w - gw1;
|
||||
double dp = dx * this.x + dy * this.y + dz * this.z + dw * this.w;
|
||||
dp /= vlen;
|
||||
return dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double dx = x - gx1;
|
||||
double dy = y - gy1;
|
||||
double dz = z - gz1;
|
||||
double dw = w - gw1;
|
||||
double du = u - gu1;
|
||||
double dv = v - gv1;
|
||||
double dp = dx * this.x + dy * this.y + dz * this.z + dw * this.w + du
|
||||
* this.u + dv * this.v;
|
||||
dp /= vlen;
|
||||
return dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(gx1).append(" ");
|
||||
sb.append(gx2).append(" ");
|
||||
sb.append(gy1).append(" ");
|
||||
sb.append(gy2).append(" ");
|
||||
sb.append(gz1).append(" ");
|
||||
sb.append(gz2).append(" ");
|
||||
sb.append(gw1).append(" ");
|
||||
sb.append(gw2).append(" ");
|
||||
sb.append(gu1).append(" ");
|
||||
sb.append(gu2).append(" ");
|
||||
sb.append(gv1).append(" ");
|
||||
sb.append(gv2);
|
||||
props.put("gradient", sb.toString());
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
String buf = props.getAsString("gradient");
|
||||
String[] arr = buf.split(" ");
|
||||
double[] d = new double[12];
|
||||
for (int i = 0; i < 12; i++) {
|
||||
d[i] = Double.parseDouble(arr[i]);
|
||||
}
|
||||
setGradient(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9],
|
||||
d[10], d[11]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleInvert extends SourcedModule {
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return -source.get(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return -source.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return -source.get(x, y, z, w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return -source.get(x, y, z, w, u, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleMagnitude extends Module {
|
||||
|
||||
protected ScalarParameter sX = new ScalarParameter(0);
|
||||
protected ScalarParameter sY = new ScalarParameter(0);
|
||||
protected ScalarParameter sZ = new ScalarParameter(0);
|
||||
protected ScalarParameter sW = new ScalarParameter(0);
|
||||
protected ScalarParameter sU = new ScalarParameter(0);
|
||||
protected ScalarParameter sV = new ScalarParameter(0);
|
||||
|
||||
public void setX(double source) {
|
||||
sX.set(source);
|
||||
}
|
||||
|
||||
public void setY(double source) {
|
||||
sY.set(source);
|
||||
}
|
||||
|
||||
public void setZ(double source) {
|
||||
sZ.set(source);
|
||||
}
|
||||
|
||||
public void setW(double source) {
|
||||
sW.set(source);
|
||||
}
|
||||
|
||||
public void setU(double source) {
|
||||
sU.set(source);
|
||||
}
|
||||
|
||||
public void setV(double source) {
|
||||
sV.set(source);
|
||||
}
|
||||
|
||||
public void setX(Module source) {
|
||||
sX.set(source);
|
||||
}
|
||||
|
||||
public void setY(Module source) {
|
||||
sY.set(source);
|
||||
}
|
||||
|
||||
public void setZ(Module source) {
|
||||
sZ.set(source);
|
||||
}
|
||||
|
||||
public void setW(Module source) {
|
||||
sW.set(source);
|
||||
}
|
||||
|
||||
public void setU(Module source) {
|
||||
sU.set(source);
|
||||
}
|
||||
|
||||
public void setV(Module source) {
|
||||
sV.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double xx = sX.get(x, y);
|
||||
double yy = sY.get(x, y);
|
||||
return Math.sqrt(xx * xx + yy * yy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double xx = sX.get(x, y, z);
|
||||
double yy = sY.get(x, y, z);
|
||||
double zz = sZ.get(x, y, z);
|
||||
return Math.sqrt(xx * xx + yy * yy + zz * zz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double xx = sX.get(x, y, z, w);
|
||||
double yy = sY.get(x, y, z, w);
|
||||
double zz = sZ.get(x, y, z, w);
|
||||
double ww = sW.get(x, y, z, w);
|
||||
return Math.sqrt(xx * xx + yy * yy + zz * zz + ww * ww);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double xx = sX.get(x, y, z, w, u, v);
|
||||
double yy = sY.get(x, y, z, w, u, v);
|
||||
double zz = sZ.get(x, y, z, w, u, v);
|
||||
double ww = sW.get(x, y, z, w, u, v);
|
||||
double uu = sU.get(x, y, z, w, u, v);
|
||||
double vv = sV.get(x, y, z, w, u, v);
|
||||
return Math.sqrt(xx * xx + yy * yy + zz * zz + ww * ww + uu * uu + vv * vv);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("X", sX, props, map);
|
||||
writeScalar("Y", sY, props, map);
|
||||
writeScalar("Z", sZ, props, map);
|
||||
writeScalar("W", sW, props, map);
|
||||
writeScalar("U", sU, props, map);
|
||||
writeScalar("V", sV, props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("X", "setX", props, map);
|
||||
readScalar("Y", "setY", props, map);
|
||||
readScalar("Z", "setZ", props, map);
|
||||
readScalar("W", "setW", props, map);
|
||||
readScalar("U", "setU", props, map);
|
||||
readScalar("V", "setV", props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleNormalizedCoords extends SourcedModule {
|
||||
|
||||
public static final double DEFAULT_LENGTH = 1.0;
|
||||
|
||||
protected ScalarParameter length = new ScalarParameter(DEFAULT_LENGTH);
|
||||
|
||||
public ModuleNormalizedCoords() {
|
||||
this(DEFAULT_LENGTH);
|
||||
}
|
||||
|
||||
public ModuleNormalizedCoords(double length) {
|
||||
setLength(length);
|
||||
}
|
||||
|
||||
public void setLength(double source) {
|
||||
length.set(source);
|
||||
}
|
||||
|
||||
public void setLength(Module source) {
|
||||
length.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
if (x == 0 && y == 0) return source.get(x, y);
|
||||
|
||||
double len = Math.sqrt(x * x + y * y);
|
||||
double r = length.get(x, y);
|
||||
return source.get(x / len * r, y / len * r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
if (x == 0 && y == 0 && z == 0) return source.get(x, y, z);
|
||||
|
||||
double len = Math.sqrt(x * x + y * y + z * z);
|
||||
double r = length.get(x, y, z);
|
||||
return source.get(x / len * r, y / len * r, z / len * r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
if (x == 0 && y == 0 && z == 0 && w == 0) return source.get(x, y, z, w);
|
||||
|
||||
double len = Math.sqrt(x * x + y * y + z * z + w * w);
|
||||
double r = length.get(x, y, z, w);
|
||||
return source.get(x / len * r, y / len * r, z / len * r, w / len * r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
if (x == 0 && y == 0 && z == 0 && w == 0 && u == 0 && v == 0)
|
||||
return source.get(x, y, z, w, u, v);
|
||||
|
||||
double len = Math.sqrt(x * x + y * y + z * z + w * w + u * u + v * v);
|
||||
double r = length.get(x, y, z, w, u, v);
|
||||
return source.get(x / len * r, y / len * r, z / len * r, w / len * r, u
|
||||
/ len * r, v / len * r);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("length", length, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("length", "setLength", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModulePow extends SourcedModule {
|
||||
|
||||
public static final double DEFAULT_POWER = 1.0;
|
||||
|
||||
protected ScalarParameter power = new ScalarParameter(DEFAULT_POWER);
|
||||
|
||||
public void setPower(double v) {
|
||||
power.set(v);
|
||||
}
|
||||
|
||||
public void setPower(Module source) {
|
||||
power.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return Math.pow(source.get(x, y), power.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return Math.pow(source.get(x, y, z), power.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return Math.pow(source.get(x, y, z, w), power.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return Math.pow(source.get(x, y, z, w, u, v), power.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("power", power, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("power", "setPower", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.noise.Util;
|
||||
|
||||
public class ModuleRotateDomain extends SourcedModule {
|
||||
|
||||
protected double[][] rotmatrix = new double[3][3];
|
||||
protected ScalarParameter ax = new ScalarParameter(0);
|
||||
protected ScalarParameter ay = new ScalarParameter(0);
|
||||
protected ScalarParameter az = new ScalarParameter(0);
|
||||
protected ScalarParameter axisangle = new ScalarParameter(0);
|
||||
|
||||
public void setAxis(double ax, double ay, double az) {
|
||||
this.ax.set(ax);
|
||||
this.ay.set(ay);
|
||||
this.az.set(az);
|
||||
}
|
||||
|
||||
public void setAxis(Module ax, Module ay, Module az) {
|
||||
this.ax.set(ax);
|
||||
this.ay.set(ay);
|
||||
this.az.set(az);
|
||||
}
|
||||
|
||||
public void setAxisX(double ax) {
|
||||
this.ax.set(ax);
|
||||
}
|
||||
|
||||
public void setAxisX(Module ax) {
|
||||
this.ax.set(ax);
|
||||
}
|
||||
|
||||
public void setAxisY(double ay) {
|
||||
this.ay.set(ay);
|
||||
}
|
||||
|
||||
public void setAxisY(Module ay) {
|
||||
this.ay.set(ay);
|
||||
}
|
||||
|
||||
public void setAxisZ(double az) {
|
||||
this.az.set(az);
|
||||
}
|
||||
|
||||
public void setAxisZ(Module az) {
|
||||
this.az.set(az);
|
||||
}
|
||||
|
||||
public void setAngle(double a) {
|
||||
this.axisangle.set(a);
|
||||
}
|
||||
|
||||
public void setAngle(Module a) {
|
||||
this.axisangle.set(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double nx, ny;
|
||||
double angle = axisangle.get(x, y) * Util.TWO_PI;
|
||||
double cos2d = Math.cos(angle);
|
||||
double sin2d = Math.sin(angle);
|
||||
nx = x * cos2d - y * sin2d;
|
||||
ny = y * cos2d + x * sin2d;
|
||||
return source.get(nx, ny);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
calculateRotMatrix(x, y, z);
|
||||
double nx, ny, nz;
|
||||
nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z);
|
||||
ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z);
|
||||
nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z);
|
||||
return source.get(nx, ny, nz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
calculateRotMatrix(x, y, z, w);
|
||||
double nx, ny, nz;
|
||||
nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z);
|
||||
ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z);
|
||||
nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z);
|
||||
return source.get(nx, ny, nz, w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
calculateRotMatrix(x, y, z, w, u, v);
|
||||
double nx, ny, nz;
|
||||
nx = (rotmatrix[0][0] * x) + (rotmatrix[1][0] * y) + (rotmatrix[2][0] * z);
|
||||
ny = (rotmatrix[0][1] * x) + (rotmatrix[1][1] * y) + (rotmatrix[2][1] * z);
|
||||
nz = (rotmatrix[0][2] * x) + (rotmatrix[1][2] * y) + (rotmatrix[2][2] * z);
|
||||
return source.get(nx, ny, nz, w, u, v);
|
||||
}
|
||||
|
||||
protected void calculateRotMatrix(double x, double y) {
|
||||
double angle = axisangle.get(x, y) * Util.TWO_PI;
|
||||
double ax = this.ax.get(x, y);
|
||||
double ay = this.ay.get(x, y);
|
||||
double az = this.az.get(x, y);
|
||||
calc(angle, ax, ay, az);
|
||||
}
|
||||
|
||||
protected void calculateRotMatrix(double x, double y, double z) {
|
||||
double angle = axisangle.get(x, y, z) * Util.TWO_PI;
|
||||
double ax = this.ax.get(x, y, z);
|
||||
double ay = this.ay.get(x, y, z);
|
||||
double az = this.az.get(x, y, z);
|
||||
calc(angle, ax, ay, az);
|
||||
}
|
||||
|
||||
protected void calculateRotMatrix(double x, double y, double z, double w) {
|
||||
double angle = axisangle.get(x, y, z, w) * Util.TWO_PI;
|
||||
double ax = this.ax.get(x, y, z, w);
|
||||
double ay = this.ay.get(x, y, z, w);
|
||||
double az = this.az.get(x, y, z, w);
|
||||
calc(angle, ax, ay, az);
|
||||
}
|
||||
|
||||
protected void calculateRotMatrix(double x, double y, double z, double w,
|
||||
double u, double v) {
|
||||
double angle = axisangle.get(x, y, z, w, u, v) * Util.TWO_PI;
|
||||
double ax = this.ax.get(x, y, z, w, u, v);
|
||||
double ay = this.ay.get(x, y, z, w, u, v);
|
||||
double az = this.az.get(x, y, z, w, u, v);
|
||||
calc(angle, ax, ay, az);
|
||||
}
|
||||
|
||||
protected void calc(double angle, double ax, double ay, double az) {
|
||||
double cosangle = Math.cos(angle);
|
||||
double sinangle = Math.sin(angle);
|
||||
|
||||
rotmatrix[0][0] = 1.0 + (1.0 - cosangle) * (ax * ax - 1.0);
|
||||
rotmatrix[1][0] = -az * sinangle + (1.0 - cosangle) * ax * ay;
|
||||
rotmatrix[2][0] = ay * sinangle + (1.0 - cosangle) * ax * az;
|
||||
|
||||
rotmatrix[0][1] = az * sinangle + (1.0 - cosangle) * ax * ay;
|
||||
rotmatrix[1][1] = 1.0 + (1.0 - cosangle) * (ay * ay - 1.0);
|
||||
rotmatrix[2][1] = -ax * sinangle + (1.0 - cosangle) * ay * az;
|
||||
|
||||
rotmatrix[0][2] = -ay * sinangle + (1.0 - cosangle) * ax * az;
|
||||
rotmatrix[1][2] = ax * sinangle + (1.0 - cosangle) * ay * az;
|
||||
rotmatrix[2][2] = 1.0 + (1.0 - cosangle) * (az * az - 1.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("axisX", ax, props, map);
|
||||
writeScalar("axisY", ay, props, map);
|
||||
writeScalar("axisZ", az, props, map);
|
||||
writeScalar("angle", axisangle, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("axisX", "setAxisX", props, map);
|
||||
readScalar("axisY", "setAxisY", props, map);
|
||||
readScalar("axisZ", "setAxisZ", props, map);
|
||||
readScalar("angle", "setAngle", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleSawtooth extends SourcedModule {
|
||||
|
||||
protected ScalarParameter period = new ScalarParameter(0);
|
||||
|
||||
public void setPeriod(double p) {
|
||||
period.set(p);
|
||||
}
|
||||
|
||||
public void setPeriod(Module p) {
|
||||
period.set(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double val = source.get(x, y) / period.get(x, y);
|
||||
return 2.0 * (val - Math.floor(0.5 + val));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double val = source.get(x, y, z) / period.get(x, y, z);
|
||||
return 2.0 * (val - Math.floor(0.5 + val));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double val = source.get(x, y, z, w) / period.get(x, y, z, w);
|
||||
return 2.0 * (val - Math.floor(0.5 + val));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double val = source.get(x, y, z, w, u, v) / period.get(x, y, z, w, u, v);
|
||||
return 2.0 * (val - Math.floor(0.5 + val));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("period", period, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("period", "setPeriod", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleScaleDomain extends SourcedModule {
|
||||
|
||||
public static final double DEFAULT_SCALE = 1.0;
|
||||
|
||||
protected ScalarParameter sx = new ScalarParameter(1.0);
|
||||
protected ScalarParameter sy = new ScalarParameter(1.0);
|
||||
protected ScalarParameter sz = new ScalarParameter(1.0);
|
||||
protected ScalarParameter sw = new ScalarParameter(1.0);
|
||||
protected ScalarParameter su = new ScalarParameter(1.0);
|
||||
protected ScalarParameter sv = new ScalarParameter(1.0);
|
||||
|
||||
public void setScaleX(double x) {
|
||||
sx.set(x);
|
||||
}
|
||||
|
||||
public void setScaleY(double y) {
|
||||
sy.set(y);
|
||||
}
|
||||
|
||||
public void setScaleZ(double z) {
|
||||
sz.set(z);
|
||||
}
|
||||
|
||||
public void setScaleW(double w) {
|
||||
sw.set(w);
|
||||
}
|
||||
|
||||
public void setScaleU(double u) {
|
||||
su.set(u);
|
||||
}
|
||||
|
||||
public void setScaleV(double v) {
|
||||
sv.set(v);
|
||||
}
|
||||
|
||||
public void setScaleX(Module x) {
|
||||
sx.set(x);
|
||||
}
|
||||
|
||||
public void setScaleY(Module y) {
|
||||
sy.set(y);
|
||||
}
|
||||
|
||||
public void setScaleZ(Module z) {
|
||||
sz.set(z);
|
||||
}
|
||||
|
||||
public void setScaleW(Module w) {
|
||||
sw.set(w);
|
||||
}
|
||||
|
||||
public void setScaleU(Module u) {
|
||||
su.set(u);
|
||||
}
|
||||
|
||||
public void setScaleV(Module v) {
|
||||
sv.set(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return source.get(x * sx.get(x, y), y * sy.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return source.get(x * sx.get(x, y, z), y * sy.get(x, y, z),
|
||||
z * sz.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return source.get(x * sx.get(x, y, z, w), y * sy.get(x, y, z, w),
|
||||
z * sz.get(x, y, z, w), w * sw.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return source.get(x * sx.get(x, y, z, w, u, v),
|
||||
y * sy.get(x, y, z, w, u, v), z * sz.get(x, y, z, w, u, v),
|
||||
w * sw.get(x, y, z, w, u, v), u * su.get(x, y, z, w, u, v),
|
||||
v * sv.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("x", sx, props, map);
|
||||
writeScalar("y", sy, props, map);
|
||||
writeScalar("z", sz, props, map);
|
||||
writeScalar("w", sw, props, map);
|
||||
writeScalar("u", su, props, map);
|
||||
writeScalar("v", sv, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("x", "setScaleX", props, map);
|
||||
readScalar("y", "setScaleY", props, map);
|
||||
readScalar("z", "setScaleZ", props, map);
|
||||
readScalar("w", "setScaleW", props, map);
|
||||
readScalar("u", "setScaleU", props, map);
|
||||
readScalar("v", "setScaleV", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleScaleOffset extends SourcedModule {
|
||||
|
||||
protected ScalarParameter scale = new ScalarParameter(1.0);
|
||||
protected ScalarParameter offset = new ScalarParameter(0.0);
|
||||
|
||||
public void setScale(double s) {
|
||||
scale.set(s);
|
||||
}
|
||||
|
||||
public void setScale(Module s) {
|
||||
scale.set(s);
|
||||
}
|
||||
|
||||
public void setOffset(double o) {
|
||||
offset.set(o);
|
||||
}
|
||||
|
||||
public void setOffset(Module o) {
|
||||
offset.set(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return source.get(x, y) * scale.get(x, y) + offset.get(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return source.get(x, y, z) * scale.get(x, y, z) + offset.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return source.get(x, y, z, w) * scale.get(x, y, z, w)
|
||||
+ offset.get(x, y, z, w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return source.get(x, y, z, w, u, v) * scale.get(x, y, z, w, u, v)
|
||||
+ offset.get(x, y, z, w, u, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("offset", offset, props, map);
|
||||
writeScalar("scale", scale, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("offset", "setOffset", props, map);
|
||||
readScalar("scale", "setScale", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.noise.Util;
|
||||
|
||||
public class ModuleSelect extends Module {
|
||||
|
||||
protected ScalarParameter low = new ScalarParameter(0);
|
||||
protected ScalarParameter high = new ScalarParameter(0);
|
||||
protected ScalarParameter control = new ScalarParameter(0);
|
||||
protected ScalarParameter threshold = new ScalarParameter(0);
|
||||
protected ScalarParameter falloff = new ScalarParameter(0);
|
||||
|
||||
public void setLowSource(double source) {
|
||||
low.set(source);
|
||||
}
|
||||
|
||||
public void setHighSource(double source) {
|
||||
high.set(source);
|
||||
}
|
||||
|
||||
public void setControlSource(double source) {
|
||||
control.set(source);
|
||||
}
|
||||
|
||||
public void setThreshold(double source) {
|
||||
threshold.set(source);
|
||||
}
|
||||
|
||||
public void setFalloff(double source) {
|
||||
falloff.set(source);
|
||||
}
|
||||
|
||||
public void setLowSource(Module source) {
|
||||
low.set(source);
|
||||
}
|
||||
|
||||
public void setHighSource(Module source) {
|
||||
high.set(source);
|
||||
}
|
||||
|
||||
public void setControlSource(Module source) {
|
||||
control.set(source);
|
||||
}
|
||||
|
||||
public void setThreshold(Module source) {
|
||||
threshold.set(source);
|
||||
}
|
||||
|
||||
public void setFalloff(Module source) {
|
||||
falloff.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double c = control.get(x, y);
|
||||
double f = falloff.get(x, y);
|
||||
double t = threshold.get(x, y);
|
||||
|
||||
if (f > 0.0) {
|
||||
|
||||
if (c < (t - f)) {
|
||||
return low.get(x, y);
|
||||
} else if (c > (t + f)) {
|
||||
return high.get(x, y);
|
||||
} else {
|
||||
double lower = t - f;
|
||||
double upper = t + f;
|
||||
double blend = Util.quinticBlend((c - lower) / (upper - lower));
|
||||
return Util.lerp(blend, low.get(x, y), high.get(x, y));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (c < t) {
|
||||
return low.get(x, y);
|
||||
} else {
|
||||
return high.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double c = control.get(x, y, z);
|
||||
double f = falloff.get(x, y, z);
|
||||
double t = threshold.get(x, y, z);
|
||||
|
||||
if (f > 0.0) {
|
||||
|
||||
if (c < (t - f)) {
|
||||
return low.get(x, y, z);
|
||||
} else if (c > (t + f)) {
|
||||
return high.get(x, y, z);
|
||||
} else {
|
||||
double lower = t - f;
|
||||
double upper = t + f;
|
||||
double blend = Util.quinticBlend((c - lower) / (upper - lower));
|
||||
return Util.lerp(blend, low.get(x, y, z), high.get(x, y, z));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (c < t) {
|
||||
return low.get(x, y, z);
|
||||
} else {
|
||||
return high.get(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double c = control.get(x, y, z, w);
|
||||
double f = falloff.get(x, y, z, w);
|
||||
double t = threshold.get(x, y, z, w);
|
||||
|
||||
if (f > 0.0) {
|
||||
|
||||
if (c < (t - f)) {
|
||||
return low.get(x, y, z, w);
|
||||
} else if (c > (t + f)) {
|
||||
return high.get(x, y, z, w);
|
||||
} else {
|
||||
double lower = t - f;
|
||||
double upper = t + f;
|
||||
double blend = Util.quinticBlend((c - lower) / (upper - lower));
|
||||
return Util.lerp(blend, low.get(x, y, z, w), high.get(x, y, z, w));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (c < t) {
|
||||
return low.get(x, y, z, w);
|
||||
} else {
|
||||
return high.get(x, y, z, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double c = control.get(x, y, z, w, u, v);
|
||||
double f = falloff.get(x, y, z, w, u, v);
|
||||
double t = threshold.get(x, y, z, w, u, v);
|
||||
|
||||
if (f > 0.0) {
|
||||
|
||||
if (c < (t - f)) {
|
||||
return low.get(x, y, z, w, u, v);
|
||||
} else if (c > (t + f)) {
|
||||
return high.get(x, y, z, w, u, v);
|
||||
} else {
|
||||
double lower = t - f;
|
||||
double upper = t + f;
|
||||
double blend = Util.quinticBlend((c - lower) / (upper - lower));
|
||||
return Util.lerp(blend, low.get(x, y, z, w, u, v),
|
||||
high.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (c < t) {
|
||||
return low.get(x, y, z, w, u, v);
|
||||
} else {
|
||||
return high.get(x, y, z, w, u, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("low", low, props, map);
|
||||
writeScalar("high", high, props, map);
|
||||
writeScalar("control", control, props, map);
|
||||
writeScalar("threshold", threshold, props, map);
|
||||
writeScalar("falloff", falloff, props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("low", "setLowSource", props, map);
|
||||
readScalar("high", "setHighSource", props, map);
|
||||
readScalar("control", "setControlSource", props, map);
|
||||
readScalar("threshold", "setThreshold", props, map);
|
||||
readScalar("falloff", "setFalloff", props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleSin extends SourcedModule {
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return Math.sin(source.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return Math.sin(source.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return Math.sin(source.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return Math.sin(source.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleSphere extends Module {
|
||||
|
||||
protected ScalarParameter cx = new ScalarParameter(0);
|
||||
protected ScalarParameter cy = new ScalarParameter(0);
|
||||
protected ScalarParameter cz = new ScalarParameter(0);
|
||||
protected ScalarParameter cw = new ScalarParameter(0);
|
||||
protected ScalarParameter cu = new ScalarParameter(0);
|
||||
protected ScalarParameter cv = new ScalarParameter(0);
|
||||
protected ScalarParameter radius = new ScalarParameter(1);
|
||||
|
||||
public void setCenterX(double source) {
|
||||
cx.set(source);
|
||||
}
|
||||
|
||||
public void setCenterY(double source) {
|
||||
cy.set(source);
|
||||
}
|
||||
|
||||
public void setCenterZ(double source) {
|
||||
cz.set(source);
|
||||
}
|
||||
|
||||
public void setCenterW(double source) {
|
||||
cw.set(source);
|
||||
}
|
||||
|
||||
public void setCenterU(double source) {
|
||||
cu.set(source);
|
||||
}
|
||||
|
||||
public void setCenterV(double source) {
|
||||
cv.set(source);
|
||||
}
|
||||
|
||||
public void setRadius(double source) {
|
||||
radius.set(source);
|
||||
}
|
||||
|
||||
public void setCenterX(Module source) {
|
||||
cx.set(source);
|
||||
}
|
||||
|
||||
public void setCenterY(Module source) {
|
||||
cy.set(source);
|
||||
}
|
||||
|
||||
public void setCenterZ(Module source) {
|
||||
cz.set(source);
|
||||
}
|
||||
|
||||
public void setCenterW(Module source) {
|
||||
cw.set(source);
|
||||
}
|
||||
|
||||
public void setCenterU(Module source) {
|
||||
cu.set(source);
|
||||
}
|
||||
|
||||
public void setCenterV(Module source) {
|
||||
cv.set(source);
|
||||
}
|
||||
|
||||
public void setRadius(Module source) {
|
||||
radius.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double dx = x - cx.get(x, y), dy = y - cy.get(x, y);
|
||||
double len = Math.sqrt(dx * dx + dy * dy);
|
||||
double r = radius.get(x, y);
|
||||
double i = (r - len) / r;
|
||||
if (i < 0) i = 0;
|
||||
if (i > 1) i = 1;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double dx = x - cx.get(x, y, z), dy = y - cy.get(x, y, z), dz = z
|
||||
- cz.get(x, y, z);
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
double r = radius.get(x, y, z);
|
||||
double i = (r - len) / r;
|
||||
if (i < 0) i = 0;
|
||||
if (i > 1) i = 1;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double dx = x - cx.get(x, y, z, w), dy = y - cy.get(x, y, z, w), dz = z
|
||||
- cz.get(x, y, z, w), dw = w - cw.get(x, y, z, w);
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
|
||||
double r = radius.get(x, y, z, w);
|
||||
double i = (r - len) / r;
|
||||
if (i < 0) i = 0;
|
||||
if (i > 1) i = 1;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double dx = x - cx.get(x, y, z, w, u, v), dy = y - cy.get(x, y, z, w, u, v), dz = z
|
||||
- cz.get(x, y, z, w, u, v), dw = w - cw.get(x, y, z, w, u, v), du = u
|
||||
- cu.get(x, y, z, w, u, v), dv = v - cv.get(x, y, z, w, u, v);
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw + du * du + dv
|
||||
* dv);
|
||||
double r = radius.get(x, y, z, w, u, v);
|
||||
double i = (r - len) / r;
|
||||
if (i < 0) i = 0;
|
||||
if (i > 1) i = 1;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("cx", cx, props, map);
|
||||
writeScalar("cy", cy, props, map);
|
||||
writeScalar("cz", cz, props, map);
|
||||
writeScalar("cw", cw, props, map);
|
||||
writeScalar("cu", cu, props, map);
|
||||
writeScalar("cv", cv, props, map);
|
||||
writeScalar("radius", radius, props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("cx", "setCenterX", props, map);
|
||||
readScalar("cy", "setCenterY", props, map);
|
||||
readScalar("cz", "setCenterZ", props, map);
|
||||
readScalar("cw", "setCenterW", props, map);
|
||||
readScalar("cu", "setCenterU", props, map);
|
||||
readScalar("cv", "setCenterV", props, map);
|
||||
readScalar("radius", "setRadius", props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.noise.Util;
|
||||
import com.sudoplay.util.Checked;
|
||||
|
||||
public class ModuleTiers extends SourcedModule {
|
||||
|
||||
public static final int DEFAULT_NUM_TIERS = 0;
|
||||
public static final boolean DEFAULT_SMOOTH = true;
|
||||
|
||||
protected int numTiers = DEFAULT_NUM_TIERS;
|
||||
protected boolean smooth = DEFAULT_SMOOTH;
|
||||
|
||||
public void setNumTiers(long n) {
|
||||
numTiers = Checked.safeLongToInt(n);
|
||||
}
|
||||
|
||||
public void setNumTiers(int n) {
|
||||
numTiers = n;
|
||||
}
|
||||
|
||||
public void setSmooth(boolean b) {
|
||||
smooth = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
int numsteps = numTiers;
|
||||
if (smooth) --numsteps;
|
||||
double val = source.get(x, y);
|
||||
double Tb = Math.floor(val * (double) (numsteps));
|
||||
double Tt = Tb + 1.0;
|
||||
double t = val * (double) (numsteps) - Tb;
|
||||
Tb /= (double) (numsteps);
|
||||
Tt /= (double) (numsteps);
|
||||
double u;
|
||||
if (smooth)
|
||||
u = Util.quinticBlend(t);
|
||||
else
|
||||
u = 0.0;
|
||||
return Tb + u * (Tt - Tb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
int numsteps = numTiers;
|
||||
if (smooth) --numsteps;
|
||||
double val = source.get(x, y, z);
|
||||
double Tb = Math.floor(val * (double) (numsteps));
|
||||
double Tt = Tb + 1.0;
|
||||
double t = val * (double) (numsteps) - Tb;
|
||||
Tb /= (double) (numsteps);
|
||||
Tt /= (double) (numsteps);
|
||||
double u;
|
||||
if (smooth)
|
||||
u = Util.quinticBlend(t);
|
||||
else
|
||||
u = 0.0;
|
||||
return Tb + u * (Tt - Tb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
int numsteps = numTiers;
|
||||
if (smooth) --numsteps;
|
||||
double val = source.get(x, y, z, w);
|
||||
double Tb = Math.floor(val * (double) (numsteps));
|
||||
double Tt = Tb + 1.0;
|
||||
double t = val * (double) (numsteps) - Tb;
|
||||
Tb /= (double) (numsteps);
|
||||
Tt /= (double) (numsteps);
|
||||
double u;
|
||||
if (smooth)
|
||||
u = Util.quinticBlend(t);
|
||||
else
|
||||
u = 0.0;
|
||||
return Tb + u * (Tt - Tb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
int numsteps = numTiers;
|
||||
if (smooth) --numsteps;
|
||||
double val = source.get(x, y, z, w, u, v);
|
||||
double Tb = Math.floor(val * (double) (numsteps));
|
||||
double Tt = Tb + 1.0;
|
||||
double t = val * (double) (numsteps) - Tb;
|
||||
Tb /= (double) (numsteps);
|
||||
Tt /= (double) (numsteps);
|
||||
double s;
|
||||
if (smooth)
|
||||
s = Util.quinticBlend(t);
|
||||
else
|
||||
s = 0.0;
|
||||
return Tb + s * (Tt - Tb);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeLong("tiers", numTiers, props);
|
||||
writeBoolean("smooth", smooth, props);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readLong("tiers", "setNumTiers", props);
|
||||
readBoolean("smooth", "setSmooth", props);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public class ModuleTranslateDomain extends SourcedModule {
|
||||
|
||||
protected ScalarParameter ax = new ScalarParameter(0);
|
||||
protected ScalarParameter ay = new ScalarParameter(0);
|
||||
protected ScalarParameter az = new ScalarParameter(0);
|
||||
protected ScalarParameter aw = new ScalarParameter(0);
|
||||
protected ScalarParameter au = new ScalarParameter(0);
|
||||
protected ScalarParameter av = new ScalarParameter(0);
|
||||
|
||||
public void setAxisXSource(double source) {
|
||||
ax.set(source);
|
||||
}
|
||||
|
||||
public void setAxisYSource(double source) {
|
||||
ay.set(source);
|
||||
}
|
||||
|
||||
public void setAxisZSource(double source) {
|
||||
az.set(source);
|
||||
}
|
||||
|
||||
public void setAxisWSource(double source) {
|
||||
aw.set(source);
|
||||
}
|
||||
|
||||
public void setAxisUSource(double source) {
|
||||
au.set(source);
|
||||
}
|
||||
|
||||
public void setAxisVSource(double source) {
|
||||
av.set(source);
|
||||
}
|
||||
|
||||
public void setAxisXSource(Module source) {
|
||||
ax.set(source);
|
||||
}
|
||||
|
||||
public void setAxisYSource(Module source) {
|
||||
ay.set(source);
|
||||
}
|
||||
|
||||
public void setAxisZSource(Module source) {
|
||||
az.set(source);
|
||||
}
|
||||
|
||||
public void setAxisWSource(Module source) {
|
||||
aw.set(source);
|
||||
}
|
||||
|
||||
public void setAxisUSource(Module source) {
|
||||
au.set(source);
|
||||
}
|
||||
|
||||
public void setAxisVSource(Module source) {
|
||||
av.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
return source.get(x + ax.get(x, y), y + ay.get(x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
return source.get(x + ax.get(x, y, z), y + ay.get(x, y, z),
|
||||
z + az.get(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
return source.get(x + ax.get(x, y, z, w), y + ay.get(x, y, z, w),
|
||||
z + az.get(x, y, z, w), w + aw.get(x, y, z, w));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
return source.get(x + ax.get(x, y, z, w, u, v),
|
||||
y + ay.get(x, y, z, w, u, v), z + az.get(x, y, z, w, u, v),
|
||||
w + aw.get(x, y, z, w, u, v), u + au.get(x, y, z, w, u, v),
|
||||
v + av.get(x, y, z, w, u, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("axisX", ax, props, map);
|
||||
writeScalar("axisY", ay, props, map);
|
||||
writeScalar("axisZ", az, props, map);
|
||||
writeScalar("axisW", aw, props, map);
|
||||
writeScalar("axisU", au, props, map);
|
||||
writeScalar("axisV", av, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("axisX", "setAxisXSource", props, map);
|
||||
readScalar("axisY", "setAxisYSource", props, map);
|
||||
readScalar("axisZ", "setAxisZSource", props, map);
|
||||
readScalar("axisW", "setAxisWSource", props, map);
|
||||
readScalar("axisU", "setAxisUSource", props, map);
|
||||
readScalar("axisV", "setAxisVSource", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
import com.sudoplay.joise.noise.Util;
|
||||
|
||||
public class ModuleTriangle extends SourcedModule {
|
||||
|
||||
public static final double DEFAULT_PERIOD = 0;
|
||||
public static final double DEFAULT_OFFSET = 0;
|
||||
|
||||
protected ScalarParameter period = new ScalarParameter(DEFAULT_PERIOD);
|
||||
protected ScalarParameter offset = new ScalarParameter(DEFAULT_OFFSET);
|
||||
|
||||
public void setPeriod(double source) {
|
||||
period.set(source);
|
||||
}
|
||||
|
||||
public void setOffset(double source) {
|
||||
offset.set(source);
|
||||
}
|
||||
|
||||
public void setPeriod(Module source) {
|
||||
period.set(source);
|
||||
}
|
||||
|
||||
public void setOffset(Module source) {
|
||||
offset.set(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y) {
|
||||
double val = source.get(x, y);
|
||||
double p = period.get(x, y);
|
||||
double o = offset.get(x, y);
|
||||
|
||||
if (o >= 1)
|
||||
return Util.sawtooth(val, p);
|
||||
else if (o <= 0)
|
||||
return 1.0 - Util.sawtooth(val, p);
|
||||
else {
|
||||
double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
|
||||
double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
|
||||
return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
|
||||
/ (1.0 - o);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z) {
|
||||
double val = source.get(x, y, z);
|
||||
double p = period.get(x, y, z);
|
||||
double o = offset.get(x, y, z);
|
||||
|
||||
if (o >= 1)
|
||||
return Util.sawtooth(val, p);
|
||||
else if (o <= 0)
|
||||
return 1.0 - Util.sawtooth(val, p);
|
||||
else {
|
||||
double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
|
||||
double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
|
||||
return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
|
||||
/ (1.0 - o);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w) {
|
||||
double val = source.get(x, y, z, w);
|
||||
double p = period.get(x, y, z, w);
|
||||
double o = offset.get(x, y, z, w);
|
||||
|
||||
if (o >= 1)
|
||||
return Util.sawtooth(val, p);
|
||||
else if (o <= 0)
|
||||
return 1.0 - Util.sawtooth(val, p);
|
||||
else {
|
||||
double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
|
||||
double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
|
||||
return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
|
||||
/ (1.0 - o);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
double val = source.get(x, y, z, w, u, v);
|
||||
double p = period.get(x, y, z, w, u, v);
|
||||
double o = offset.get(x, y, z, w, u, v);
|
||||
|
||||
if (o >= 1)
|
||||
return Util.sawtooth(val, p);
|
||||
else if (o <= 0)
|
||||
return 1.0 - Util.sawtooth(val, p);
|
||||
else {
|
||||
double s1 = (o - Util.sawtooth(val, p)) >= 0 ? 1.0 : 0.0;
|
||||
double s2 = ((1.0 - o) - (Util.sawtooth(-val, p))) >= 0 ? 1.0 : 0.0;
|
||||
return Util.sawtooth(val, p) * s1 / o + Util.sawtooth(-val, p) * s2
|
||||
/ (1.0 - o);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _writeToMap(ModuleMap map) {
|
||||
|
||||
ModulePropertyMap props = new ModulePropertyMap(this);
|
||||
|
||||
writeScalar("offset", offset, props, map);
|
||||
writeScalar("period", period, props, map);
|
||||
writeSource(props, map);
|
||||
|
||||
map.put(getId(), props);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module buildFromPropertyMap(ModulePropertyMap props,
|
||||
ModuleInstanceMap map) {
|
||||
|
||||
readScalar("offset", "setOffset", props, map);
|
||||
readScalar("period", "setPeriod", props, map);
|
||||
readSource(props, map);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
public class ScalarParameter {
|
||||
|
||||
private Module module;
|
||||
private double value;
|
||||
|
||||
public ScalarParameter(Module source) {
|
||||
set(source);
|
||||
}
|
||||
|
||||
public ScalarParameter(double source) {
|
||||
set(source);
|
||||
}
|
||||
|
||||
public void set(Module source) {
|
||||
module = source;
|
||||
}
|
||||
|
||||
public void set(double source) {
|
||||
module = null;
|
||||
value = source;
|
||||
}
|
||||
|
||||
public boolean isModule() {
|
||||
return module != null;
|
||||
}
|
||||
|
||||
public Module getModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public double get(double x, double y) {
|
||||
if (module != null) return module.get(x, y);
|
||||
return value;
|
||||
}
|
||||
|
||||
public double get(double x, double y, double z) {
|
||||
if (module != null) return module.get(x, y, z);
|
||||
return value;
|
||||
}
|
||||
|
||||
public double get(double x, double y, double z, double w) {
|
||||
if (module != null) return module.get(x, y, z, w);
|
||||
return value;
|
||||
}
|
||||
|
||||
public double get(double x, double y, double z, double w, double u, double v) {
|
||||
if (module != null) return module.get(x, y, z, w, u, v);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (module != null) {
|
||||
return module.getId();
|
||||
} else {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public abstract class SeedableModule extends Module {
|
||||
|
||||
protected long seed = DEFAULT_SEED;
|
||||
|
||||
protected String seedName;
|
||||
|
||||
public void setSeed(long seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
public void setSeedName(String name) {
|
||||
seedName = name;
|
||||
}
|
||||
|
||||
public String getSeedName() {
|
||||
return seedName;
|
||||
}
|
||||
|
||||
public boolean hasSeedName() {
|
||||
return seedName != null;
|
||||
}
|
||||
|
||||
protected void readSeed(ModulePropertyMap props) {
|
||||
String sn = (String) props.get("seedName");
|
||||
if (sn != null) {
|
||||
seedName = sn;
|
||||
}
|
||||
setSeed(props.getAsLong("seed"));
|
||||
}
|
||||
|
||||
protected void writeSeed(ModulePropertyMap props) {
|
||||
if (seedName != null) {
|
||||
props.put("seedName", seedName);
|
||||
}
|
||||
props.put("seed", seed);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.module;
|
||||
|
||||
import com.sudoplay.joise.ModuleInstanceMap;
|
||||
import com.sudoplay.joise.ModuleMap;
|
||||
import com.sudoplay.joise.ModulePropertyMap;
|
||||
|
||||
public abstract class SourcedModule extends Module {
|
||||
|
||||
protected ScalarParameter source = new ScalarParameter(0.0);
|
||||
|
||||
public void setSource(double source) {
|
||||
this.source.set(source);
|
||||
}
|
||||
|
||||
public void setSource(Module source) {
|
||||
this.source.set(source);
|
||||
}
|
||||
|
||||
public ScalarParameter getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
protected void writeSource(ModulePropertyMap props, ModuleMap map) {
|
||||
writeScalar("source", source, props, map);
|
||||
}
|
||||
|
||||
protected void readSource(ModulePropertyMap props, ModuleInstanceMap map) {
|
||||
readScalar("source", "setSource", props, map);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.noise;
|
||||
|
||||
public interface Interpolator {
|
||||
|
||||
public static final Interpolator NONE = new Interpolator() {
|
||||
@Override
|
||||
public double interpolate(double t) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Interpolator LINEAR = new Interpolator() {
|
||||
@Override
|
||||
public double interpolate(double t) {
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Interpolator HERMITE = new Interpolator() {
|
||||
@Override
|
||||
public double interpolate(double t) {
|
||||
return (t * t * (3 - 2 * t));
|
||||
}
|
||||
};
|
||||
|
||||
public static final Interpolator QUINTIC = new Interpolator() {
|
||||
@Override
|
||||
public double interpolate(double t) {
|
||||
return t * t * t * (t * (t * 6 - 15) + 10);
|
||||
}
|
||||
};
|
||||
|
||||
public double interpolate(double t);
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.joise.noise;
|
||||
|
||||
public class Util {
|
||||
|
||||
public static final double TWO_PI = Math.PI * 2.0;
|
||||
|
||||
private static final double INV_LOG_HALF = 1.0 / Math.log(0.5);
|
||||
|
||||
private Util() {}
|
||||
|
||||
public static double clamp(double input, double min, double max) {
|
||||
return (input < min) ? min : (input > max) ? max : input;
|
||||
}
|
||||
|
||||
public static double bias(double b, double t) {
|
||||
return Math.pow(t, Math.log(b) * INV_LOG_HALF);
|
||||
}
|
||||
|
||||
public static double lerp(double t, double a, double b) {
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
public static double gain(double g, double t) {
|
||||
g = clamp(g, 0.0, 1.0);
|
||||
if (t < 0.5) {
|
||||
return bias(1.0 - g, 2.0 * t) * 0.5;
|
||||
} else {
|
||||
return 1.0 - bias(1.0 - g, 2.0 - 2.0 * t) * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
public static double quinticBlend(double t) {
|
||||
return t * t * t * (t * (t * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
public static double sawtooth(double x, double p) {
|
||||
return (2.0 * (x / p - Math.floor(0.5 + x / p))) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
public static class Vector3d {
|
||||
public double x, y, z;
|
||||
|
||||
public Vector3d() {
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Vector3d(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.util;
|
||||
|
||||
public class Assert {
|
||||
|
||||
public static void notNull(Object... objects) {
|
||||
for (Object o : objects) {
|
||||
if (o == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void hasLength(Object[] objects, int length) {
|
||||
if (objects == null && length > 0) {
|
||||
throw new IllegalArgumentException("Expecting " + length
|
||||
+ " objects but was null");
|
||||
} else if (objects.length != length) {
|
||||
throw new IllegalArgumentException("Expecting " + length
|
||||
+ " objects but was " + objects.length);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isClassNotNull(Class<?> c, Object... objects) {
|
||||
for (Object o : objects) {
|
||||
if (o == null) {
|
||||
throw new NullPointerException("Expecting " + c.getName()
|
||||
+ " but was null");
|
||||
} else if (!c.equals(o.getClass())) {
|
||||
throw new IllegalArgumentException("Expecting " + c.getName()
|
||||
+ " but was " + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void isInstanceNotNull(Class<?> c, Object... objects) {
|
||||
for (Object o : objects) {
|
||||
if (o == null) {
|
||||
throw new NullPointerException("Expecting " + c.getName()
|
||||
+ " but was null");
|
||||
} else if (!c.isInstance(o)) {
|
||||
throw new IllegalArgumentException("Expecting " + c.getName()
|
||||
+ " but was " + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void isClass(Class<?> c, Object... objects) {
|
||||
for (Object o : objects) {
|
||||
if (!c.equals(o.getClass())) {
|
||||
throw new IllegalArgumentException("Expecting " + c.getName()
|
||||
+ " but was " + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void isInstance(Class<?> c, Object... objects) {
|
||||
for (Object o : objects) {
|
||||
if (!c.isInstance(o)) {
|
||||
throw new IllegalArgumentException("Expecting " + c.getName()
|
||||
+ " but was " + o.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T isInstance(Class<T> c, Object o) {
|
||||
if (!c.isInstance(o)) {
|
||||
throw new IllegalArgumentException("Expecting " + c.getName()
|
||||
+ " but was " + o.getClass().getName());
|
||||
}
|
||||
return c.cast(o);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Jason Taylor.
|
||||
* Released as open-source under the Apache License, Version 2.0.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Joise
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2013 Jason Taylor
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ============================================================================
|
||||
* | Accidental Noise Library
|
||||
* | --------------------------------------------------------------------------
|
||||
* | Joise is a derivative work based on Josua Tippetts' C++ library:
|
||||
* | http://accidentalnoise.sourceforge.net/index.html
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2011 Joshua Tippetts
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package com.sudoplay.util;
|
||||
|
||||
public class Checked {
|
||||
|
||||
private Checked() {}
|
||||
|
||||
public static int safeLongToInt(long l) {
|
||||
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
|
||||
throw new IllegalArgumentException(l
|
||||
+ " cannot be cast to int without changing its value.");
|
||||
}
|
||||
return (int) l;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
package net.torvald.aa
|
||||
|
||||
import net.torvald.terrarum.gameworld.toUint
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal
|
||||
import org.newdawn.slick.*
|
||||
|
||||
/**
|
||||
* @param terminal: for sending redraw only
|
||||
*
|
||||
* Created by minjaesong on 16-08-10.
|
||||
*/
|
||||
class AAFrame @Throws(SlickException::class)
|
||||
constructor(var width: Int, var height: Int, var terminal: SimpleTextTerminal) {
|
||||
/*class AAFrame(var width: Int, var height: Int, var terminal: SimpleTextTerminal) {
|
||||
|
||||
/**
|
||||
* 0000_0000_00000000
|
||||
@@ -94,4 +91,4 @@ constructor(var width: Int, var height: Int, var terminal: SimpleTextTerminal) {
|
||||
private fun checkOOB(x: Int, y: Int) = (x < 0 || y < 0 || x >= width || y >= height)
|
||||
|
||||
fun getColourKey(x: Int, y: Int): Int = frameBuffer[y * width + x].toInt().ushr(8).and(0xFF)
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -7,8 +7,7 @@ import net.torvald.colourutil.CIELabUtil.toLab
|
||||
import net.torvald.colourutil.CIEXYZUtil.toXYZ
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
/**
|
||||
* Cylindrical modification of CIELab colour space
|
||||
*
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
import net.torvald.colourutil.CIEXYZUtil.toRGB
|
||||
import net.torvald.colourutil.CIEXYZUtil.toXYZ
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* A modification of CIEXYZ that is useful for surface colours
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.colourutil.CIELabUtil.toXYZ
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
import net.torvald.colourutil.CIEXYZUtil.toRGB
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-01-12.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* 6-Step RGB with builtin utils.
|
||||
@@ -31,18 +31,18 @@ class Col216 : LimitedColours {
|
||||
create(r, g, b)
|
||||
}
|
||||
|
||||
override fun createSlickColor(raw: Int): Color {
|
||||
override fun createGdxColor(raw: Int): Color {
|
||||
assertRaw(raw)
|
||||
val r = raw / MUL_2
|
||||
val g = raw % MUL_2 / MUL
|
||||
val b = raw % MUL
|
||||
|
||||
return createSlickColor(r, g, b)
|
||||
return createGdxColor(r, g, b)
|
||||
}
|
||||
|
||||
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||
override fun createGdxColor(r: Int, g: Int, b: Int): Color {
|
||||
assertRGB(r, g, b)
|
||||
return Color(LOOKUP[r], LOOKUP[g], LOOKUP[b])
|
||||
return Color((LOOKUP[r] shl 24) + (LOOKUP[g] shl 16) + (LOOKUP[b] shl 8) + 255)
|
||||
}
|
||||
|
||||
override fun create(raw: Int) {
|
||||
@@ -55,7 +55,7 @@ class Col216 : LimitedColours {
|
||||
raw = (MUL_2 * r + MUL * g + b).toByte()
|
||||
}
|
||||
|
||||
override fun toSlickColour(): Color = createSlickColor(raw.toUint())
|
||||
override fun toGdxColour(): Color = createGdxColor(raw.toUint())
|
||||
|
||||
private fun assertRaw(i: Int) {
|
||||
if (i >= COLOUR_RANGE_SIZE || i < 0) {
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.torvald.colourutil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
* 40-Step RGB with builtin utils.
|
||||
* Created by minjaesong on 16-02-20.
|
||||
*/
|
||||
class Col40 : LimitedColours {
|
||||
|
||||
var raw: Char = ' '
|
||||
private set
|
||||
|
||||
override fun createSlickColor(raw: Int): Color {
|
||||
assertRaw(raw)
|
||||
val r = raw / MUL_2
|
||||
val g = raw % MUL_2 / MUL
|
||||
val b = raw % MUL
|
||||
|
||||
return createSlickColor(r, g, b)
|
||||
}
|
||||
|
||||
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||
assertRGB(r, g, b)
|
||||
return Color(LOOKUP[r] shl 16 or (LOOKUP[g] shl 8) or LOOKUP[b])
|
||||
}
|
||||
|
||||
override fun create(raw: Int) {
|
||||
assertRaw(raw)
|
||||
this.raw = raw.toChar()
|
||||
}
|
||||
|
||||
override fun create(r: Int, g: Int, b: Int) {
|
||||
assertRGB(r, g, b)
|
||||
raw = (MUL_2 * r + MUL * g + b).toChar()
|
||||
}
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
constructor(c: Color) {
|
||||
create(
|
||||
Math.round(c.r * (MUL - 1)),
|
||||
Math.round(c.g * (MUL - 1)),
|
||||
Math.round(c.b * (MUL - 1)))
|
||||
}
|
||||
|
||||
private fun assertRaw(i: Int) {
|
||||
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
||||
println("i: " + i.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertRGB(r: Int, g: Int, b: Int) {
|
||||
if (r !in 0..MAX_STEP || g !in 0..MAX_STEP || b !in 0..MAX_STEP) {
|
||||
println("r: " + r.toString())
|
||||
println("g: " + g.toString())
|
||||
println("b: " + b.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Transient private val LOOKUP = intArrayOf(0, 7, 13, 20, 26, 33, 39, 46, 52, 59, 65, 72, 78, 85, 92, 98, 105, 111, 118, 124, 131, 137, 144, 150, 157, 163, 170, 177, 183, 190, 196, 203, 209, 216, 222, 229, 235, 242, 248, 255)
|
||||
|
||||
const val MUL = 40
|
||||
const val MUL_2 = MUL * MUL
|
||||
const val MAX_STEP = MUL - 1
|
||||
const val COLOUR_DOMAIN_SIZE = MUL_2 * MUL
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* 12-bit (16-step) RGB with builtin utils.
|
||||
@@ -41,7 +41,7 @@ class Col4096 : LimitedColours {
|
||||
* *
|
||||
* @return
|
||||
*/
|
||||
override fun createSlickColor(raw: Int): Color {
|
||||
override fun createGdxColor(raw: Int): Color {
|
||||
assertRaw(raw)
|
||||
|
||||
val a: Int
|
||||
@@ -57,22 +57,22 @@ class Col4096 : LimitedColours {
|
||||
a = raw and 0xF000 shr 12
|
||||
|
||||
return Color(
|
||||
r.shl(4) or r, g.shl(4) or g, b.shl(4) or b, a.shl(4) or a)
|
||||
(r.shl(4) or r).shl(24) + (g.shl(4) or g).shl(16) + (b.shl(4) or b).shl(8) + (a.shl(4) or a))
|
||||
}
|
||||
else {
|
||||
return Color(
|
||||
r.shl(4) or r, g.shl(4) or g, b.shl(4) or b)
|
||||
(r.shl(4) or r).shl(24) + (g.shl(4) or g).shl(16) + (b.shl(4) or b).shl(8) + 255)
|
||||
}
|
||||
}
|
||||
|
||||
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||
override fun createGdxColor(r: Int, g: Int, b: Int): Color {
|
||||
assertARGB(0, r, g, b)
|
||||
return createSlickColor(r.shl(8) or g.shl(4) or b)
|
||||
return createGdxColor(r.shl(8) or g.shl(4) or b)
|
||||
}
|
||||
|
||||
fun createSlickColor(a: Int, r: Int, g: Int, b: Int): Color {
|
||||
assertARGB(a, r, g, b)
|
||||
return createSlickColor(a.shl(12) or r.shl(8) or g.shl(4) or b)
|
||||
return createGdxColor(a.shl(12) or r.shl(8) or g.shl(4) or b)
|
||||
}
|
||||
|
||||
override fun create(raw: Int) {
|
||||
@@ -107,7 +107,7 @@ class Col4096 : LimitedColours {
|
||||
return ret
|
||||
}
|
||||
|
||||
override fun toSlickColour(): Color = createSlickColor(raw.toUint())
|
||||
override fun toGdxColour(): Color = createGdxColor(raw.toUint())
|
||||
|
||||
private fun assertRaw(i: Int) {
|
||||
if (i > 0xFFFF || i < 0) {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import net.torvald.terrarum.getPixel
|
||||
import net.torvald.terrarum.weather.toColor
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.Image
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.colourutil.CIEXYZUtil.toColor
|
||||
import net.torvald.terrarum.GdxColorMap
|
||||
import net.torvald.terrarum.ModMgr
|
||||
|
||||
/**
|
||||
@@ -12,7 +10,7 @@ import net.torvald.terrarum.ModMgr
|
||||
* Created by minjaesong on 16-07-26.
|
||||
*/
|
||||
object ColourTemp {
|
||||
private var clut = Image(ModMgr.getPath("basegame", "colourmap/black_body_col_1000_40000_K.tga"))
|
||||
private var clut = GdxColorMap(ModMgr.getGdxFile("basegame", "colourmap/black_body_col_1000_40000_K.tga"))
|
||||
|
||||
private fun colTempToImagePos(K: Int): Int {
|
||||
if (K < 1000 || K >= 40000) throw IllegalArgumentException("K: out of range. ($K)")
|
||||
@@ -21,7 +19,7 @@ object ColourTemp {
|
||||
|
||||
/** returns sRGB-normalised colour */
|
||||
operator fun invoke(temp: Int): Color =
|
||||
clut.getPixel(colTempToImagePos(temp), 0).toColor()
|
||||
clut.get(colTempToImagePos(temp))
|
||||
|
||||
/** returns CIExyY-based colour converted to slick.color
|
||||
* @param CIE_Y 0.0 - 1.0+ */
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-07-26.
|
||||
*/
|
||||
object ColourUtil {
|
||||
fun toSlickColor(r: Int, g: Int, b: Int) = Color(r.shl(16) or g.shl(8) or b)
|
||||
fun toColor(r: Int, g: Int, b: Int) = Color(r.shl(24) or g.shl(16) or b.shl(8) or 0xff)
|
||||
|
||||
/**
|
||||
* Use CIELabUtil.getGradient for natural-looking colour
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* OBSOLETE; use CIELchUtil for natural-looking colour
|
||||
@@ -17,9 +17,6 @@ object HSVUtil {
|
||||
* @param S 0-1 Saturation
|
||||
* *
|
||||
* @param V 0-1 Value
|
||||
* *
|
||||
* @return org.newdawn.slick.Color
|
||||
* *
|
||||
* @link http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
|
||||
*/
|
||||
fun toRGB(H: Float, S: Float, V: Float, alpha: Float = 1f): Color {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package net.torvald.colourutil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-11.
|
||||
*/
|
||||
interface LimitedColours {
|
||||
|
||||
fun createSlickColor(raw: Int): Color
|
||||
fun createSlickColor(r: Int, g: Int, b: Int): Color
|
||||
fun createGdxColor(raw: Int): Color
|
||||
fun createGdxColor(r: Int, g: Int, b: Int): Color
|
||||
|
||||
fun create(raw: Int)
|
||||
fun create(r: Int, g: Int, b: Int)
|
||||
|
||||
fun toSlickColour(): Color
|
||||
fun toGdxColour(): Color
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package net.torvald.imagefont
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.Font
|
||||
import org.newdawn.slick.SpriteSheet
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-04-15.
|
||||
*/
|
||||
class TinyAlphNum : Font {
|
||||
|
||||
internal val fontSheet: SpriteSheet
|
||||
|
||||
internal val W = 8
|
||||
internal val H = 8
|
||||
|
||||
/*private val chars = arrayOf(
|
||||
'0','1','2','3','4','5','6','7',
|
||||
'8','9','[','#','@',':','>','?',
|
||||
' ','A','B','C','D','E','F','G',
|
||||
'H','I','&','.',']','(','<','\\',
|
||||
'^','J','K','L','M','N','O','P',
|
||||
'Q','R','-','¤','*',')',';','\'',
|
||||
'+','/','S','T','U','V','W','X',
|
||||
'Y','Z','_',',','%','=','"','!'
|
||||
)
|
||||
private val mappingTable = HashMap<Int, Int>()*/
|
||||
|
||||
init {
|
||||
fontSheet = SpriteSheet("./assets/graphics/fonts/milky.tga", W, H)
|
||||
//chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i }
|
||||
}
|
||||
|
||||
override fun getHeight(str: String): Int = H
|
||||
|
||||
override fun getWidth(str: String): Int {
|
||||
var ret = 0
|
||||
for (i in 0..str.length - 1) {
|
||||
val c = str.codePointAt(i).toChar()
|
||||
if (!c.isColourCode())
|
||||
ret += W
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
override fun getLineHeight(): Int = H
|
||||
|
||||
override fun drawString(x: Float, y: Float, text: String) = drawString(x, y, text, Color.white)
|
||||
|
||||
override fun drawString(x: Float, y: Float, text: String, col: Color) {
|
||||
var thisCol = col
|
||||
var textPosOffset = 0
|
||||
for (i in 0..text.length - 1) {
|
||||
//val index = charToSpriteNum(text.toUpperCase().codePointAt(i))
|
||||
val ch = text[i]
|
||||
val index = ch.toInt() and 0xFF
|
||||
|
||||
if (ch.isColourCode()) {
|
||||
thisCol = GameFontBase.colourKey[ch]!!
|
||||
continue
|
||||
}
|
||||
|
||||
fontSheet.getSubImage(index % 16, index / 16).drawWithShadow(
|
||||
x + textPosOffset, y, thisCol, false
|
||||
)
|
||||
|
||||
textPosOffset += W
|
||||
}
|
||||
}
|
||||
|
||||
override fun drawString(x: Float, y: Float, text: String, col: Color, startIndex: Int, endIndex: Int) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
//private fun charToSpriteNum(ch: Int): Int? = mappingTable[ch]
|
||||
|
||||
fun Char.isColourCode() = GameFontBase.colourKey.containsKey(this)
|
||||
}
|
||||
@@ -1,328 +0,0 @@
|
||||
package net.torvald.slick.opengl;
|
||||
|
||||
/*
|
||||
* A utility to load .tga.gz
|
||||
*
|
||||
* Created by SKYHi14 on 2017-04-19.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.newdawn.slick.opengl.LoadableImageData;
|
||||
|
||||
/**
|
||||
* A utility to load TGAs. Note: NOT THREAD SAFE
|
||||
*
|
||||
* Fresh cut of code but largely influeneced by the TGA loading class
|
||||
* provided as part of the Java Monkey Engine (JME). Why not check out
|
||||
* what they're doing over at http://www.jmonkeyengine.com. kudos to
|
||||
* Mark Powell.
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public class TGAGzImageData implements LoadableImageData {
|
||||
/** The width of the texture that needs to be generated */
|
||||
private int texWidth;
|
||||
/** The height of the texture that needs to be generated */
|
||||
private int texHeight;
|
||||
/** The width of the TGA image */
|
||||
private int width;
|
||||
/** The height of the TGA image */
|
||||
private int height;
|
||||
/** The bit depth of the image */
|
||||
private short pixelDepth;
|
||||
|
||||
/**
|
||||
* Create a new TGA Loader
|
||||
*/
|
||||
public TGAGzImageData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip the endian-ness of the short
|
||||
*
|
||||
* @param signedShort The short to flip
|
||||
* @return The flipped short
|
||||
*/
|
||||
private short flipEndian(short signedShort) {
|
||||
int input = signedShort & 0xFFFF;
|
||||
return (short) (input << 8 | (input & 0xFF00) >>> 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.ImageData#getDepth()
|
||||
*/
|
||||
public int getDepth() {
|
||||
return pixelDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.ImageData#getWidth()
|
||||
*/
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.ImageData#getHeight()
|
||||
*/
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.ImageData#getTexWidth()
|
||||
*/
|
||||
public int getTexWidth() {
|
||||
return texWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.ImageData#getTexHeight()
|
||||
*/
|
||||
public int getTexHeight() {
|
||||
return texHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream)
|
||||
*/
|
||||
public ByteBuffer loadImage(InputStream fis) throws IOException {
|
||||
return loadImage(fis,true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, int[])
|
||||
*/
|
||||
public ByteBuffer loadImage(InputStream fis, boolean flipped, int[] transparent) throws IOException {
|
||||
return loadImage(fis, flipped, false, transparent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[])
|
||||
*/
|
||||
public ByteBuffer loadImage(InputStream fis, boolean flipped, boolean forceAlpha, int[] transparent) throws IOException {
|
||||
if (transparent != null) {
|
||||
forceAlpha = true;
|
||||
}
|
||||
byte red = 0;
|
||||
byte green = 0;
|
||||
byte blue = 0;
|
||||
byte alpha = 0;
|
||||
|
||||
BufferedInputStream bis = new BufferedInputStream(new GZIPInputStream(fis, 8192), 16384);
|
||||
DataInputStream dis = new DataInputStream(bis);
|
||||
|
||||
// Read in the Header
|
||||
short idLength = (short) dis.read();
|
||||
short colorMapType = (short) dis.read();
|
||||
short imageType = (short) dis.read();
|
||||
short cMapStart = flipEndian(dis.readShort());
|
||||
short cMapLength = flipEndian(dis.readShort());
|
||||
short cMapDepth = (short) dis.read();
|
||||
short xOffset = flipEndian(dis.readShort());
|
||||
short yOffset = flipEndian(dis.readShort());
|
||||
|
||||
if (imageType != 2) {
|
||||
throw new IOException("Slick only supports uncompressed RGB(A) TGA images");
|
||||
}
|
||||
|
||||
width = flipEndian(dis.readShort());
|
||||
height = flipEndian(dis.readShort());
|
||||
pixelDepth = (short) dis.read();
|
||||
if (pixelDepth == 32) {
|
||||
forceAlpha = false;
|
||||
}
|
||||
|
||||
texWidth = get2Fold(width);
|
||||
texHeight = get2Fold(height);
|
||||
|
||||
short imageDescriptor = (short) dis.read();
|
||||
if ((imageDescriptor & 0x0020) == 0) {
|
||||
flipped = !flipped;
|
||||
}
|
||||
|
||||
// Skip image ID
|
||||
if (idLength > 0) {
|
||||
bis.skip(idLength);
|
||||
}
|
||||
|
||||
byte[] rawData = null;
|
||||
if ((pixelDepth == 32) || (forceAlpha)) {
|
||||
pixelDepth = 32;
|
||||
rawData = new byte[texWidth * texHeight * 4];
|
||||
} else if (pixelDepth == 24) {
|
||||
rawData = new byte[texWidth * texHeight * 3];
|
||||
} else {
|
||||
throw new RuntimeException("Only 24 and 32 bit TGAs are supported");
|
||||
}
|
||||
|
||||
if (pixelDepth == 24) {
|
||||
if (flipped) {
|
||||
for (int i = height-1; i >= 0; i--) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
blue = dis.readByte();
|
||||
green = dis.readByte();
|
||||
red = dis.readByte();
|
||||
|
||||
int ofs = ((j + (i * texWidth)) * 3);
|
||||
rawData[ofs] = red;
|
||||
rawData[ofs + 1] = green;
|
||||
rawData[ofs + 2] = blue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
blue = dis.readByte();
|
||||
green = dis.readByte();
|
||||
red = dis.readByte();
|
||||
|
||||
int ofs = ((j + (i * texWidth)) * 3);
|
||||
rawData[ofs] = red;
|
||||
rawData[ofs + 1] = green;
|
||||
rawData[ofs + 2] = blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pixelDepth == 32) {
|
||||
if (flipped) {
|
||||
for (int i = height-1; i >= 0; i--) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
blue = dis.readByte();
|
||||
green = dis.readByte();
|
||||
red = dis.readByte();
|
||||
if (forceAlpha) {
|
||||
alpha = (byte) 255;
|
||||
} else {
|
||||
alpha = dis.readByte();
|
||||
}
|
||||
|
||||
int ofs = ((j + (i * texWidth)) * 4);
|
||||
|
||||
rawData[ofs] = red;
|
||||
rawData[ofs + 1] = green;
|
||||
rawData[ofs + 2] = blue;
|
||||
rawData[ofs + 3] = alpha;
|
||||
|
||||
if (alpha == 0) {
|
||||
rawData[ofs + 2] = (byte) 0;
|
||||
rawData[ofs + 1] = (byte) 0;
|
||||
rawData[ofs] = (byte) 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
blue = dis.readByte();
|
||||
green = dis.readByte();
|
||||
red = dis.readByte();
|
||||
if (forceAlpha) {
|
||||
alpha = (byte) 255;
|
||||
} else {
|
||||
alpha = dis.readByte();
|
||||
}
|
||||
|
||||
int ofs = ((j + (i * texWidth)) * 4);
|
||||
|
||||
if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
|
||||
rawData[ofs] = red;
|
||||
rawData[ofs + 1] = green;
|
||||
rawData[ofs + 2] = blue;
|
||||
rawData[ofs + 3] = alpha;
|
||||
} else {
|
||||
rawData[ofs] = red;
|
||||
rawData[ofs + 1] = green;
|
||||
rawData[ofs + 2] = blue;
|
||||
rawData[ofs + 3] = alpha;
|
||||
}
|
||||
|
||||
if (alpha == 0) {
|
||||
rawData[ofs + 2] = 0;
|
||||
rawData[ofs + 1] = 0;
|
||||
rawData[ofs] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fis.close();
|
||||
|
||||
if (transparent != null) {
|
||||
for (int i=0;i<rawData.length;i+=4) {
|
||||
boolean match = true;
|
||||
for (int c=0;c<3;c++) {
|
||||
if (rawData[i+c] != transparent[c]) {
|
||||
match = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (match) {
|
||||
rawData[i+3] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get a pointer to the image memory
|
||||
ByteBuffer scratch = BufferUtils.createByteBuffer(rawData.length);
|
||||
scratch.put(rawData);
|
||||
|
||||
int perPixel = pixelDepth / 8;
|
||||
if (height < texHeight-1) {
|
||||
int topOffset = (texHeight-1) * (texWidth*perPixel);
|
||||
int bottomOffset = (height-1) * (texWidth*perPixel);
|
||||
for (int x=0;x<texWidth*perPixel;x++) {
|
||||
scratch.put(topOffset+x, scratch.get(x));
|
||||
scratch.put(bottomOffset+(texWidth*perPixel)+x, scratch.get((texWidth*perPixel)+x));
|
||||
}
|
||||
}
|
||||
if (width < texWidth-1) {
|
||||
for (int y=0;y<texHeight;y++) {
|
||||
for (int i=0;i<perPixel;i++) {
|
||||
scratch.put(((y+1)*(texWidth*perPixel))-perPixel+i, scratch.get(y*(texWidth*perPixel)+i));
|
||||
scratch.put((y*(texWidth*perPixel))+(width*perPixel)+i, scratch.get((y*(texWidth*perPixel))+((width-1)*perPixel)+i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scratch.flip();
|
||||
|
||||
return scratch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the closest greater power of 2 to the fold number
|
||||
*
|
||||
* @param fold The target number
|
||||
* @return The power of 2
|
||||
*/
|
||||
private int get2Fold(int fold) {
|
||||
int ret = 2;
|
||||
while (ret < fold) {
|
||||
ret *= 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.ImageData#getImageBufferData()
|
||||
*/
|
||||
public ByteBuffer getImageBufferData() {
|
||||
throw new RuntimeException("TGAImageData doesn't store it's image.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.opengl.LoadableImageData#configureEdging(boolean)
|
||||
*/
|
||||
public void configureEdging(boolean edging) {
|
||||
}
|
||||
}
|
||||
@@ -4,50 +4,44 @@
|
||||
|
||||
package net.torvald.spriteanimation
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.gameactors.ActorWithPhysics
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.SlickException
|
||||
import org.newdawn.slick.SpriteSheet
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
class SpriteAnimation(val parentActor: ActorWithPhysics, val cellWidth: Int, val cellHeight: Int) {
|
||||
class SpriteAnimation(val parentActor: ActorWithPhysics) {
|
||||
|
||||
private lateinit var textureRegion: TextureRegionPack
|
||||
|
||||
private var spriteImage: SpriteSheet? = null
|
||||
var currentFrame = 0
|
||||
var currentRow = 0
|
||||
var nFrames: Int = 1
|
||||
private set
|
||||
var nRows: Int = 1
|
||||
private set
|
||||
var delay = 200
|
||||
private var delta = 0
|
||||
var delay = 200f
|
||||
private var delta = 0f
|
||||
val looping = true
|
||||
private var animationRunning = true
|
||||
private var flipHorizontal = false
|
||||
private var flipVertical = false
|
||||
var flipHorizontal = false
|
||||
var flipVertical = false
|
||||
private val visible: Boolean
|
||||
get() = parentActor.isVisible
|
||||
|
||||
private val offsetX = 0
|
||||
private val offsetY = 0
|
||||
|
||||
private var prevScale = 1f
|
||||
private var currentImage: Image? = null
|
||||
var cellWidth: Int = 0
|
||||
var cellHeight: Int = 0
|
||||
|
||||
/**
|
||||
* Sets spritesheet.
|
||||
* MUST be called AFTER setDimension.
|
||||
* @param imagePath path to the sprite sheet image.
|
||||
* *
|
||||
* @throws SlickException
|
||||
*/
|
||||
fun setSpriteImage(imagePath: String) {
|
||||
spriteImage = SpriteSheet(imagePath, cellWidth, cellHeight)
|
||||
}
|
||||
var colorFilter = Color.WHITE
|
||||
|
||||
fun setSpriteImage(image: Image) {
|
||||
spriteImage = SpriteSheet(image, cellWidth, cellHeight)
|
||||
fun setSpriteImage(regionPack: TextureRegionPack) {
|
||||
textureRegion = regionPack
|
||||
|
||||
cellWidth = regionPack.tileW
|
||||
cellHeight = regionPack.tileH
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +56,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics, val cellWidth: Int, val
|
||||
this.nFrames = nFrames
|
||||
}
|
||||
|
||||
fun update(delta: Int) {
|
||||
fun update(delta: Float) {
|
||||
if (animationRunning) {
|
||||
//skip this if animation is stopped
|
||||
this.delta += delta
|
||||
@@ -76,7 +70,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics, val cellWidth: Int, val
|
||||
|
||||
//advance one frame, then reset delta counter
|
||||
this.currentFrame = this.currentFrame % this.nFrames
|
||||
this.delta = 0
|
||||
this.delta = 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,25 +86,17 @@ class SpriteAnimation(val parentActor: ActorWithPhysics, val cellWidth: Int, val
|
||||
* *
|
||||
* @param scale
|
||||
*/
|
||||
@JvmOverloads fun render(g: Graphics, posX: Float, posY: Float, scale: Float = 1f) {
|
||||
@JvmOverloads fun render(batch: SpriteBatch, posX: Float, posY: Float, scale: Float = 1f) {
|
||||
if (cellWidth == 0 || cellHeight == 0) {
|
||||
throw Error("Sprite width or height is set to zero! ($cellWidth, $cellHeight); master: $parentActor")
|
||||
}
|
||||
|
||||
// Null checking
|
||||
if (currentImage == null) {
|
||||
currentImage = getScaledSprite(scale)
|
||||
}
|
||||
|
||||
if (visible) {
|
||||
// re-scale image if scale has been changed
|
||||
if (prevScale != scale) {
|
||||
currentImage = getScaledSprite(scale)
|
||||
prevScale = scale
|
||||
}
|
||||
val region = textureRegion.get(currentRow, currentFrame)
|
||||
region.flip(flipHorizontal, !flipVertical)
|
||||
batch.color = colorFilter
|
||||
|
||||
val flippedImage = currentImage!!.getFlippedCopy(flipHorizontal, flipVertical)
|
||||
flippedImage.draw(
|
||||
batch.draw(region,
|
||||
Math.round(posX).toFloat(),
|
||||
FastMath.floor(posY).toFloat(),
|
||||
FastMath.floor(cellWidth * scale).toFloat(),
|
||||
@@ -128,7 +114,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics, val cellWidth: Int, val
|
||||
}
|
||||
}
|
||||
|
||||
fun setSpriteDelay(newDelay: Int) {
|
||||
fun setSpriteDelay(newDelay: Float) {
|
||||
if (newDelay > 0) {
|
||||
delay = newDelay
|
||||
}
|
||||
@@ -169,17 +155,4 @@ class SpriteAnimation(val parentActor: ActorWithPhysics, val cellWidth: Int, val
|
||||
flipVertical = vertical
|
||||
}
|
||||
|
||||
fun flippedHorizontal(): Boolean {
|
||||
return flipHorizontal
|
||||
}
|
||||
|
||||
fun flippedVertical(): Boolean {
|
||||
return flipVertical
|
||||
}
|
||||
|
||||
private fun getScaledSprite(scale: Float): Image {
|
||||
val selectedImage = spriteImage!!.getSprite(currentFrame, currentRow)
|
||||
selectedImage.filter = Image.FILTER_NEAREST
|
||||
return selectedImage.getScaledCopy(scale)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.Input
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
|
||||
@@ -20,7 +20,7 @@ object DefaultConfig {
|
||||
|
||||
jsonObject.addProperty("smoothlighting", true)
|
||||
jsonObject.addProperty("imtooyoungtodie", false) // perma-death
|
||||
jsonObject.addProperty("language", Terrarum.sysLang)
|
||||
jsonObject.addProperty("language", TerrarumGDX.sysLang)
|
||||
jsonObject.addProperty("notificationshowuptime", 6500)
|
||||
jsonObject.addProperty("multithread", true) // experimental!
|
||||
|
||||
@@ -47,31 +47,31 @@ object DefaultConfig {
|
||||
|
||||
|
||||
// control-keyboard (Java key codes. This is what Minecraft also uses)
|
||||
jsonObject.addProperty("keyup", Key.E)
|
||||
jsonObject.addProperty("keyleft", Key.S)
|
||||
jsonObject.addProperty("keydown", Key.D)
|
||||
jsonObject.addProperty("keyright", Key.F)
|
||||
jsonObject.addProperty("keyup", Input.Keys.E)
|
||||
jsonObject.addProperty("keyleft", Input.Keys.S)
|
||||
jsonObject.addProperty("keydown", Input.Keys.D)
|
||||
jsonObject.addProperty("keyright", Input.Keys.F)
|
||||
|
||||
jsonObject.addProperty("keymovementaux", Key.A) // movement-auxiliary, or hookshot
|
||||
jsonObject.addProperty("keyinventory", Key.W)
|
||||
jsonObject.addProperty("keyinteract", Key.R)
|
||||
jsonObject.addProperty("keyclose", Key.C)
|
||||
jsonObject.addProperty("keymovementaux", Input.Keys.A) // movement-auxiliary, or hookshot
|
||||
jsonObject.addProperty("keyinventory", Input.Keys.W)
|
||||
jsonObject.addProperty("keyinteract", Input.Keys.R)
|
||||
jsonObject.addProperty("keyclose", Input.Keys.C)
|
||||
|
||||
jsonObject.addProperty("keygamemenu", Key.TAB)
|
||||
jsonObject.addProperty("keygamemenu", Input.Keys.TAB)
|
||||
jsonObject.addProperty("keyquicksel", Key.CAPS_LOCK) // pie menu
|
||||
val keyquickselalt = JsonArray(); keyquickselalt.add(Key.BACKSPACE); keyquickselalt.add(Key.L_COMMAND); keyquickselalt.add(Key.L_CONTROL)
|
||||
val keyquickselalt = JsonArray(); keyquickselalt.add(Input.Keys.BACKSPACE); keyquickselalt.add(Key.L_COMMAND); keyquickselalt.add(Input.Keys.CONTROL_LEFT)
|
||||
// Colemak, Workman and some typers use CapsLock as Backspace, Apple-JIS and HHKB has Control in place of CapsLock and often re-assigned to Command
|
||||
// so these keys are treated as the same.
|
||||
// FOR ~~FUCKS~~ERGONOMICS' SAKE DON'T USE CTRL AND ALT AS A KEY!
|
||||
jsonObject.add("keyquickselalt", keyquickselalt)
|
||||
|
||||
jsonObject.addProperty("keyjump", Key.SPACE)
|
||||
jsonObject.addProperty("keyjump", Input.Keys.SPACE)
|
||||
|
||||
val keyquickbars = JsonArray(); for (i in 2..11) keyquickbars.add(i) // NUM_1 to NUM_0
|
||||
jsonObject.add("keyquickbars", keyquickbars)
|
||||
|
||||
jsonObject.addProperty("mouseprimary", 0) // left mouse
|
||||
jsonObject.addProperty("mousesecondary", 1) // right mouse
|
||||
jsonObject.addProperty("mouseprimary", Input.Buttons.LEFT) // left mouse
|
||||
jsonObject.addProperty("mousesecondary", Input.Buttons.RIGHT) // right mouse
|
||||
|
||||
|
||||
jsonObject.addProperty("pcgamepadenv", "console")
|
||||
|
||||
57
src/net/torvald/terrarum/GdxColorMap.kt
Normal file
57
src/net/torvald/terrarum/GdxColorMap.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import javax.naming.OperationNotSupportedException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-17.
|
||||
*/
|
||||
|
||||
typealias XRGB888 = Int
|
||||
|
||||
class GdxColorMap {
|
||||
|
||||
constructor(imageFile: FileHandle) {
|
||||
val pixmap = Pixmap(imageFile)
|
||||
width = pixmap.width
|
||||
height = pixmap.height
|
||||
is2D = pixmap.height == 1
|
||||
|
||||
data = kotlin.IntArray(pixmap.width * pixmap.height, {
|
||||
pixmap.getPixel(it % pixmap.width, it / pixmap.width)
|
||||
})
|
||||
|
||||
pixmap.dispose()
|
||||
}
|
||||
|
||||
constructor(xrgb888: XRGB888) {
|
||||
data = intArrayOf(xrgb888.shl(24) + xrgb888.shl(16) + xrgb888.shl(8) + 255)
|
||||
width = 1
|
||||
height = 1
|
||||
is2D = false
|
||||
}
|
||||
|
||||
constructor(gradStart: XRGB888, gradEnd: XRGB888) {
|
||||
data = intArrayOf(gradStart.shl(24) + gradStart.shl(16) + gradStart.shl(8) + 255,
|
||||
gradEnd.shl(24) + gradEnd.shl(16) + gradEnd.shl(8) + 255)
|
||||
width = 1
|
||||
height = 2
|
||||
is2D = true
|
||||
}
|
||||
|
||||
private val data: IntArray
|
||||
val width: Int
|
||||
val height: Int
|
||||
val is2D: Boolean
|
||||
|
||||
|
||||
|
||||
fun get(x: Int, y: Int): Color = Color(data[y * width + x])
|
||||
operator fun get(x: Int): Color = if (!is2D) throw OperationNotSupportedException("This is 2D color map") else Color(data[x])
|
||||
|
||||
fun getRaw(x: Int, y: Int): RGBA8888 = data[y * width + x]
|
||||
fun getRaw(x: Int): RGBA8888 = if (!is2D) throw OperationNotSupportedException("This is 2D color map") else data[x]
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
@@ -115,6 +117,9 @@ object ModMgr {
|
||||
checkExistence(module)
|
||||
return "$modDir/$module/${path.sanitisePath()}"
|
||||
}
|
||||
fun getGdxFile(module: String, path: String): FileHandle {
|
||||
return Gdx.files.internal(getPath(module, path))
|
||||
}
|
||||
fun getFile(module: String, path: String): File {
|
||||
checkExistence(module)
|
||||
return FileSystems.getDefault().getPath(getPath(module, path)).toFile()
|
||||
|
||||
@@ -1,347 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.gameactors.floor
|
||||
import net.torvald.terrarum.gameactors.floorInt
|
||||
import net.torvald.terrarum.gameworld.toUint
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.nio.ByteOrder
|
||||
|
||||
|
||||
/**
|
||||
* Software rendering test for blur
|
||||
*
|
||||
* Created by minjaesong on 2017-01-12.
|
||||
*/
|
||||
class StateBlurTest : BasicGameState() {
|
||||
|
||||
/** Warning: the image must have a bit depth of 32! (use 32-bit PNG or TGA) */
|
||||
private val testImage = Image("./assets/test_texture.tga")
|
||||
private val bluredImage = ImageBuffer(testImage.width, testImage.height)
|
||||
|
||||
override fun init(gc: GameContainer, sbg: StateBasedGame) {
|
||||
/*testImage.flushPixelData()
|
||||
|
||||
System.arraycopy(
|
||||
testImage.texture.textureData, 0,
|
||||
bluredImage.rgba, 0, testImage.texture.textureData.size
|
||||
)*/
|
||||
//kotlin.repeat(3) { fastBoxBlur(bluredImage, 3) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}")
|
||||
|
||||
theta += delta / 500f
|
||||
if (theta > FastMath.TWO_PI)
|
||||
theta -= FastMath.TWO_PI
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_BLUR
|
||||
|
||||
var theta = 0f
|
||||
|
||||
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
||||
System.arraycopy(
|
||||
testImage.texture.textureData, 0,
|
||||
bluredImage.rgba, 0, testImage.texture.textureData.size
|
||||
)
|
||||
kotlin.repeat(3) { fastBoxBlur(bluredImage, 3) }
|
||||
|
||||
g.background = Color(0x404040)
|
||||
val image = bluredImage.image // ImageBuffer.getImage() always HARDCOPIES texture data by
|
||||
// allocating new ByteBuffer. We need variable so that we can destroy() it manually
|
||||
g.drawImage(image,
|
||||
Terrarum.WIDTH.minus(testImage.width).div(2f).floor() + FastMath.cos(theta) * 120,
|
||||
Terrarum.HEIGHT.minus(testImage.height).div(2f).floor() + FastMath.sin(theta) * 40
|
||||
)
|
||||
g.flush()
|
||||
|
||||
image.destroy() // You are done and you will be terminated, for the perkeleen memory's sake
|
||||
}
|
||||
|
||||
private val isLE: Boolean
|
||||
get() = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN
|
||||
|
||||
/** three iterations of box blur \simeq gaussian blur */
|
||||
fun fastBoxBlur(from: Image, to: ImageBuffer, radius: Int) {
|
||||
|
||||
/** 0xRRGGBBAA */
|
||||
fun getPixelData(index: Int): Int {
|
||||
val r = from.texture.textureData[4 * index + if (isLE) 0 else 2].toUint()
|
||||
val g = from.texture.textureData[4 * index + 1].toUint()
|
||||
val b = from.texture.textureData[4 * index + if (isLE) 2 else 0].toUint()
|
||||
|
||||
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
|
||||
return r.shl(16) or g.shl(8) or b
|
||||
}
|
||||
else {
|
||||
return b.shl(16) or g.shl(8) or r
|
||||
}
|
||||
}
|
||||
|
||||
/** alpha will be passed through */
|
||||
fun setPixelData(index: Int, value: Int) {
|
||||
val r = value.ushr(24).and(0xff)
|
||||
val g = value.ushr(16).and(0xff)
|
||||
val b = value.ushr(8).and(0xff)
|
||||
|
||||
to.rgba[4 * index + if (isLE) 0 else 2] = r.toByte()
|
||||
to.rgba[4 * index + 1] = g.toByte()
|
||||
to.rgba[4 * index + if (isLE) 2 else 0] = b.toByte()
|
||||
}
|
||||
|
||||
if (radius < 1) {
|
||||
return
|
||||
}
|
||||
val w = to.texWidth
|
||||
val h = to.texHeight
|
||||
val wm = w - 1
|
||||
val hm = h - 1
|
||||
val wh = w * h
|
||||
val div = radius + radius + 1
|
||||
val r = IntArray(wh)
|
||||
val g = IntArray(wh)
|
||||
val b = IntArray(wh)
|
||||
var rsum: Int
|
||||
var gsum: Int
|
||||
var bsum: Int
|
||||
var x: Int
|
||||
var y: Int
|
||||
var i: Int
|
||||
var p: Int
|
||||
var p1: Int
|
||||
var p2: Int
|
||||
var yp: Int
|
||||
var yi: Int
|
||||
var yw: Int
|
||||
val vmin = IntArray(Math.max(w, h))
|
||||
val vmax = IntArray(Math.max(w, h))
|
||||
|
||||
//img.getPixels(pix, 0, w, 0, 0, w, h)
|
||||
|
||||
val dv = IntArray(256 * div)
|
||||
i = 0
|
||||
while (i < 256 * div) {
|
||||
dv[i] = i / div
|
||||
i++
|
||||
}
|
||||
|
||||
yi = 0
|
||||
yw = yi
|
||||
|
||||
y = 0
|
||||
while (y < h) {
|
||||
bsum = 0
|
||||
gsum = bsum
|
||||
rsum = gsum
|
||||
i = -radius
|
||||
while (i <= radius) {
|
||||
p = getPixelData(yi + Math.min(wm, Math.max(i, 0)))
|
||||
rsum += p and 0xff0000 shr 16
|
||||
gsum += p and 0x00ff00 shr 8
|
||||
bsum += p and 0x0000ff
|
||||
i++
|
||||
}
|
||||
x = 0
|
||||
while (x < w) {
|
||||
|
||||
r[yi] = dv[rsum]
|
||||
g[yi] = dv[gsum]
|
||||
b[yi] = dv[bsum]
|
||||
|
||||
if (y == 0) {
|
||||
vmin[x] = Math.min(x + radius + 1, wm)
|
||||
vmax[x] = Math.max(x - radius, 0)
|
||||
}
|
||||
p1 = getPixelData(yw + vmin[x])
|
||||
p2 = getPixelData(yw + vmax[x])
|
||||
|
||||
rsum += (p1 and 0xff0000) - (p2 and 0xff0000) shr 16
|
||||
gsum += (p1 and 0x00ff00) - (p2 and 0x00ff00) shr 8
|
||||
bsum += (p1 and 0x0000ff) - (p2 and 0x0000ff)
|
||||
yi++
|
||||
x++
|
||||
}
|
||||
yw += w
|
||||
y++
|
||||
}
|
||||
|
||||
x = 0
|
||||
while (x < w) {
|
||||
bsum = 0
|
||||
gsum = bsum
|
||||
rsum = gsum
|
||||
yp = -radius * w
|
||||
i = -radius
|
||||
while (i <= radius) {
|
||||
yi = Math.max(0, yp) + x
|
||||
rsum += r[yi]
|
||||
gsum += g[yi]
|
||||
bsum += b[yi]
|
||||
yp += w
|
||||
i++
|
||||
}
|
||||
yi = x
|
||||
y = 0
|
||||
while (y < h) {
|
||||
setPixelData(yi, dv[rsum].shl(24) or dv[gsum].shl(16) or dv[bsum].shl(8))
|
||||
|
||||
if (x == 0) {
|
||||
vmin[y] = Math.min(y + radius + 1, hm) * w
|
||||
vmax[y] = Math.max(y - radius, 0) * w
|
||||
}
|
||||
p1 = x + vmin[y]
|
||||
p2 = x + vmax[y]
|
||||
|
||||
rsum += r[p1] - r[p2]
|
||||
gsum += g[p1] - g[p2]
|
||||
bsum += b[p1] - b[p2]
|
||||
|
||||
yi += w
|
||||
y++
|
||||
}
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
fun fastBoxBlur(img: ImageBuffer, radius: Int) {
|
||||
|
||||
/** 0xRRGGBBAA */
|
||||
fun getPixelData(index: Int): Int {
|
||||
val r = img.rgba[4 * index].toUint()
|
||||
val g = img.rgba[4 * index + 1].toUint()
|
||||
val b = img.rgba[4 * index + 2].toUint()
|
||||
|
||||
return r.shl(16) or g.shl(8) or b
|
||||
}
|
||||
|
||||
/** alpha will be passed through */
|
||||
fun setPixelData(index: Int, value: Int) {
|
||||
val r = value.ushr(24).and(0xff)
|
||||
val g = value.ushr(16).and(0xff)
|
||||
val b = value.ushr(8).and(0xff)
|
||||
|
||||
img.rgba[4 * index] = r.toByte()
|
||||
img.rgba[4 * index + 1] = g.toByte()
|
||||
img.rgba[4 * index + 2] = b.toByte()
|
||||
}
|
||||
|
||||
if (radius < 1) {
|
||||
return
|
||||
}
|
||||
val w = img.texWidth
|
||||
val h = img.texHeight
|
||||
val wm = w - 1
|
||||
val hm = h - 1
|
||||
val wh = w * h
|
||||
val div = radius + radius + 1
|
||||
val r = IntArray(wh)
|
||||
val g = IntArray(wh)
|
||||
val b = IntArray(wh)
|
||||
var rsum: Int
|
||||
var gsum: Int
|
||||
var bsum: Int
|
||||
var x: Int
|
||||
var y: Int
|
||||
var i: Int
|
||||
var p: Int
|
||||
var p1: Int
|
||||
var p2: Int
|
||||
var yp: Int
|
||||
var yi: Int
|
||||
var yw: Int
|
||||
val vmin = IntArray(Math.max(w, h))
|
||||
val vmax = IntArray(Math.max(w, h))
|
||||
|
||||
//img.getPixels(pix, 0, w, 0, 0, w, h)
|
||||
|
||||
val dv = IntArray(256 * div)
|
||||
i = 0
|
||||
while (i < 256 * div) {
|
||||
dv[i] = i / div
|
||||
i++
|
||||
}
|
||||
|
||||
yi = 0
|
||||
yw = yi
|
||||
|
||||
y = 0
|
||||
while (y < h) {
|
||||
bsum = 0
|
||||
gsum = bsum
|
||||
rsum = gsum
|
||||
i = -radius
|
||||
while (i <= radius) {
|
||||
p = getPixelData(yi + Math.min(wm, Math.max(i, 0)))
|
||||
rsum += p and 0xff0000 shr 16
|
||||
gsum += p and 0x00ff00 shr 8
|
||||
bsum += p and 0x0000ff
|
||||
i++
|
||||
}
|
||||
x = 0
|
||||
while (x < w) {
|
||||
|
||||
r[yi] = dv[rsum]
|
||||
g[yi] = dv[gsum]
|
||||
b[yi] = dv[bsum]
|
||||
|
||||
if (y == 0) {
|
||||
vmin[x] = Math.min(x + radius + 1, wm)
|
||||
vmax[x] = Math.max(x - radius, 0)
|
||||
}
|
||||
p1 = getPixelData(yw + vmin[x])
|
||||
p2 = getPixelData(yw + vmax[x])
|
||||
|
||||
rsum += (p1 and 0xff0000) - (p2 and 0xff0000) shr 16
|
||||
gsum += (p1 and 0x00ff00) - (p2 and 0x00ff00) shr 8
|
||||
bsum += (p1 and 0x0000ff) - (p2 and 0x0000ff)
|
||||
yi++
|
||||
x++
|
||||
}
|
||||
yw += w
|
||||
y++
|
||||
}
|
||||
|
||||
x = 0
|
||||
while (x < w) {
|
||||
bsum = 0
|
||||
gsum = bsum
|
||||
rsum = gsum
|
||||
yp = -radius * w
|
||||
i = -radius
|
||||
while (i <= radius) {
|
||||
yi = Math.max(0, yp) + x
|
||||
rsum += r[yi]
|
||||
gsum += g[yi]
|
||||
bsum += b[yi]
|
||||
yp += w
|
||||
i++
|
||||
}
|
||||
yi = x
|
||||
y = 0
|
||||
while (y < h) {
|
||||
setPixelData(yi, dv[rsum].shl(24) or dv[gsum].shl(16) or dv[bsum].shl(8))
|
||||
|
||||
if (x == 0) {
|
||||
vmin[y] = Math.min(y + radius + 1, hm) * w
|
||||
vmax[y] = Math.max(y - radius, 0) * w
|
||||
}
|
||||
p1 = x + vmin[y]
|
||||
p2 = x + vmax[y]
|
||||
|
||||
rsum += r[p1] - r[p2]
|
||||
gsum += g[p1] - g[p2]
|
||||
bsum += b[p1] - b[p2]
|
||||
|
||||
yi += w
|
||||
y++
|
||||
}
|
||||
x++
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-15.
|
||||
*/
|
||||
class StateControllerRumbleTest : BasicGameState() {
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle("${GAME_NAME} — Do not pull out the controller!")
|
||||
|
||||
KeyToggler.update(container.input)
|
||||
|
||||
if (Terrarum.controller != null) {
|
||||
for (i in 0..minOf(rumblerCount - 1, 9)) {
|
||||
Terrarum.controller!!.setRumblerStrength(i, if (KeyToggler.isOn(2 + i)) 1f else 0f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var rumblerCount = Terrarum.controller?.rumblerCount ?: 0
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TOOL_RUMBLE_DIAGNOSIS
|
||||
|
||||
override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
g.font = Terrarum.fontGame
|
||||
g.color = Color.white
|
||||
|
||||
if (Terrarum.controller != null) {
|
||||
g.drawString("Controller: ${Terrarum.controller!!.name}", 10f, 10f)
|
||||
g.drawString("Rumbler count: ${rumblerCount}", 10f, 30f)
|
||||
g.drawString("Rumblers", 10f, 70f)
|
||||
for (i in 0..minOf(rumblerCount - 1, 9)) {
|
||||
g.color = if (KeyToggler.isOn(2 + i)) Color(0x55ff55) else Color(0x808080)
|
||||
//g.drawString("$i", 10f + i * 16f, 90f)
|
||||
|
||||
g.drawString("$i — ${Terrarum.controller!!.getRumblerName(i)}", 10f, 90f + 20 * i)
|
||||
}
|
||||
}
|
||||
else {
|
||||
g.drawString("Controller not found.", 10f, 10f)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.imagefont.GameFontImpl
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-06-28.
|
||||
*/
|
||||
class StateFontTester : BasicGameState() {
|
||||
val textToPrint = """
|
||||
ABCDEFGHIJKLM
|
||||
NOPQRSTUVWXYZ
|
||||
|
||||
abcdefghijklm
|
||||
nopqrstuvwxyz
|
||||
|
||||
1234567890
|
||||
"""
|
||||
|
||||
lateinit var canvas: Graphics
|
||||
|
||||
//lateinit var segfont: Font
|
||||
|
||||
lateinit var mtfont: Font
|
||||
|
||||
override fun init(gc: GameContainer, game: StateBasedGame) {
|
||||
canvas = Graphics(1024, 1024)
|
||||
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
|
||||
g.background = Color(0x282828)
|
||||
g.font = Terrarum.fontGame
|
||||
|
||||
|
||||
g.drawString("ABCDEFGHIJKLMN", 10f, 10f)
|
||||
g.drawString("OPQRSTÜVWXYZÆŒ", 10f, 30f)
|
||||
|
||||
g.drawString("abcdefghijklmno", 160f, 10f)
|
||||
g.drawString("pqrstuvwxyzßæœ", 160f, 30f)
|
||||
|
||||
g.drawString("1234567890?!", 320f, 10f)
|
||||
//g.drawString("minimum kerning keming Narnu Namu", 320f, 30f)
|
||||
|
||||
//g.drawString("Syö salmiakkia perkele", 480f, 10f)
|
||||
|
||||
/*val text = arrayOf(
|
||||
"The bitmap font for game developers who seek good font that has real multilingual support,",
|
||||
"for free (as in freedom AND without cost).",
|
||||
"",
|
||||
"There are many bitmap fonts on the internet. You care for the multilingual support, but alas!",
|
||||
"most of them do not support your language, vector fonts take too much time to load, and even",
|
||||
"then their legibility suffers because fuck built-in antialias.",
|
||||
"You somehow found a fine one, and it makes your game look like a linux terminal, and you say:",
|
||||
"“Well, better than nothing *sigh*; No, it’s ugly.”",
|
||||
"You speak Japanese, and you wish to support it, but then このクソなfontは only good for Japanese,",
|
||||
"it is not even multilingual, and their English look ugly and inconsistent anyway.",
|
||||
"Eventually you just use different fonts together, and the result was always mildly infuriating.",
|
||||
"",
|
||||
"No more suffering. This font has everything you need.",
|
||||
"",
|
||||
"while (isVisible(BadFonts)) { ripAndTear(BadFonts).scope(Guts); }",
|
||||
"How multilingual? Real multilingual!",
|
||||
"",
|
||||
"Příliš žluťoučký kůň úpěl ďábelské ódy",
|
||||
"Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich",
|
||||
"διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα",
|
||||
"ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ",
|
||||
"Pack my box with five dozen liquor jugs",
|
||||
"Voix ambiguë d'un cœur qui au zéphyr préfère les jattes de kiwi",
|
||||
"정 참판 양반댁 규수 큰 교자 타고 혼례 치른 날 하얬다 도럄직한 퀡봹퉪헰",
|
||||
"Kæmi ný öxi hér, ykist þjófum nú bæði víl og ádrepa",
|
||||
"Árvíztűrő tükörfúrógép Kŕdeľ ďatľov učí koňa žrať kôru",
|
||||
"とりなくこゑす ゆめさませ みよあけわたる ひんかしを そらいろはえて おきつへに ほふねむれゐぬ もやのうち",
|
||||
"鳥啼ク声ス 夢覚マセ 見ヨ明ク渡ル 東ヲ 空色栄エテ 沖ツ辺ニ 帆船群レヰヌ 靄ノ中",
|
||||
"Înjurând pițigăiat, zoofobul comandă vexat whisky și tequila",
|
||||
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства",
|
||||
"Pijamalı hasta yağız şoföre çabucak güvendi",
|
||||
"Also supports: ‛Unicode’ „quotation marks“—dashes…「括弧」‼",
|
||||
"ASCII Latin-1 Latin_Ext-A Latin_Ext-B Greek Cyrillic CJK-Ideo Kana Hangul_Syllables",
|
||||
"",
|
||||
"…not seeing your language/writing system? Let me know on the Issue Tracker!"
|
||||
)*/
|
||||
val text = arrayOf(
|
||||
"x64またはx86-64とは、x86アーキテクチャを64ビットに拡張した命令セットアーキテクチャ。",
|
||||
"実際には、AMDが発表したAMD64命令セット、続けてインテルが採用したIntel 64命令セット (かつてIA-32eまたはEM64Tと呼ばれていた)",
|
||||
"などを含む、各社のAMD64互換命令セットの総称である。x86命令セットと互換性を持っていることから、広義にはx86にx64を含む場合がある。",
|
||||
"",
|
||||
"x86-64는 x86 명령어 집합 아키텍처의 64비트 모임이다. x86-64 명령어 집합은 에뮬레이션 없이 인텔의 x86를 지원하며 AMD64로 이름 붙인",
|
||||
"AMD에 의해 고안되었다. 이 아키텍처는 인텔 64라는 이름으로 인텔에 의해 복제되기도 했다. (옘힐, 클래카마스 기술, CT, IA-32e, EM64T 등으로",
|
||||
"불렸음) 이로써 x86-64 또는 x64의 이름을 일상적으로 사용하기에 이르렀다.",
|
||||
"",
|
||||
"x86-64 (также AMD64/Intel64/EM64T) — 64-битное расширение, набор команд для архитектуры x86, разработанное",
|
||||
"компанией AMD, позволяющее выполнять программы в 64-разрядном режиме. Это расширение архитектуры x86 с",
|
||||
"почти полной обратной совместимостью.",
|
||||
"",
|
||||
"Επίσης η x86-64 έχει καταχωρητές γενικής χρήσης 64-bit και πολλές άλλες βελτιώσεις. Η αρχική προδιαγραφή",
|
||||
"δημιουργήθηκε από την AMD και έχει υλοποιηθεί από την AMD, την Intel, τη VIA και άλλες εταιρείες. Διατηρεί πλήρη",
|
||||
"συμβατότητα προς τα πίσω με κώδικα 32-bit.",
|
||||
"",
|
||||
"x86-64 (簡稱x64) 是64位版本的x86指令集,向后相容於16位及32位的x86架構。x64於1999年由AMD設計,AMD首次公開",
|
||||
"64位元集以擴充給x86,稱為「AMD64」。其後也為英特爾所採用,現時英特爾稱之為「Intel 64」,在之前曾使用過「Clackamas",
|
||||
"Technology」 (CT)、「IA-32e」及「EM64T」",
|
||||
"",
|
||||
"x86-64, ou x64, est une extension du jeu d'instructions x86 d'Intel, introduite par la société AMD avec la gamme",
|
||||
"AMD64. Intel utilisera cette extension en l'appelant initialement EM64T renommé aujourd'hui en Intel 64.",
|
||||
"",
|
||||
"Amd64 (також x86-64/intel64/em64t/x64) — 64-бітова архітектура мікропроцесора і відповідний набір інструкцій,",
|
||||
"розроблені компанією AMD. Це розширення архітектури x86 з повною зворотною сумісністю.",
|
||||
"",
|
||||
"x86-64 е наименованието на наборът от 64-битови разширения към x86 процесорната архитектура. Като синоним",
|
||||
"на това наименование, се използват и съкращенията AMD64 (използвано от AMD), EM64T и IA-32e (използвани от",
|
||||
"Intel) и x64 (използвано от Microsoft)."
|
||||
)
|
||||
val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
||||
|
||||
/*val text = arrayOf(
|
||||
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"p]}$SP${0xe011.toChar()}..${0xe019.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}"
|
||||
)*/
|
||||
|
||||
Terrarum.gameLocale = "bgBG"
|
||||
|
||||
text.forEachIndexed { i, s ->
|
||||
g.drawString(s, 10f, 70f + 20 * i)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*val text = arrayOf(
|
||||
"ru: Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства",
|
||||
"bg: Под южно дърво, цъфтящо в синьо, бягаше малко пухкаво зайче",
|
||||
"sr: Ајшо, лепото и чежњо, за љубав срца мога дођи у Хаџиће на кафу"
|
||||
)*/
|
||||
/*val text = arrayOf(
|
||||
"……退魔の剣に選ばれし ハイラルの勇者よ",
|
||||
"その たゆまぬ努力と 結実せに剣技を認め……",
|
||||
"女神ハイリアの名において祝福を授けん……",
|
||||
"空を舞い 時を回り 黄昏に染まろうとも……",
|
||||
"結ばれし剣は 勇者の魂と共に……",
|
||||
"さらなる力が そなたと そして退魔の剣に宿らんことを……"
|
||||
)*/
|
||||
|
||||
|
||||
/*(0..text.size - 1).forEach {
|
||||
g.drawString(text[it], 10f, 70f + 20 * it)
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
override fun getID(): Int = Terrarum.STATE_ID_TEST_FONT
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum.delta
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.peripheral.PeripheralVideoCard
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.GraphicsTerminal
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-02-23.
|
||||
*/
|
||||
class StateGraphicComputerTest : BasicGameState() {
|
||||
val computer = TerrarumComputer(8)
|
||||
val monitor = GraphicsTerminal(computer)
|
||||
|
||||
val monitorUI: Image
|
||||
val monitorUIG: Graphics
|
||||
|
||||
init {
|
||||
val videocard = PeripheralVideoCard(computer)
|
||||
monitor.attachVideoCard(videocard)
|
||||
|
||||
computer.attachTerminal(monitor)
|
||||
computer.attachPeripheral(videocard)
|
||||
|
||||
monitorUI = Image(videocard.width, videocard.height * 2)
|
||||
monitorUIG = monitorUI.graphics
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
/*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram
|
||||
|
||||
// it's a-me, Mario!
|
||||
(0..3).forEach {
|
||||
vcard.sprites[it].setPaletteSet(64,33,12,62)
|
||||
vcard.sprites[it].isVisible = true
|
||||
vcard.sprites[it].drawWide = true
|
||||
}
|
||||
|
||||
vcard.sprites[0].setAll(intArrayOf(
|
||||
0,0,0,0,0,1,1,1,
|
||||
0,0,0,0,1,1,1,1,
|
||||
0,0,0,0,2,2,2,3,
|
||||
0,0,0,2,3,2,3,3,
|
||||
0,0,0,2,3,2,2,3,
|
||||
0,0,0,2,2,3,3,3,
|
||||
0,0,0,0,0,3,3,3,
|
||||
0,0,0,0,2,2,1,2
|
||||
))
|
||||
vcard.sprites[1].setAll(intArrayOf(
|
||||
1,1,0,0,0,0,0,0,
|
||||
1,1,1,1,1,0,0,0,
|
||||
3,2,3,0,0,0,0,0,
|
||||
3,2,3,3,3,0,0,0,
|
||||
3,3,2,3,3,3,0,0,
|
||||
3,2,2,2,2,0,0,0,
|
||||
3,3,3,3,0,0,0,0,
|
||||
2,2,0,0,0,0,0,0
|
||||
))
|
||||
vcard.sprites[2].setAll(intArrayOf(
|
||||
0,0,0,2,2,2,1,2,
|
||||
0,0,2,2,2,2,1,1,
|
||||
0,0,3,3,2,1,3,1,
|
||||
0,0,3,3,3,1,1,1,
|
||||
0,0,3,3,1,1,1,1,
|
||||
0,0,0,0,1,1,1,0,
|
||||
0,0,0,2,2,2,0,0,
|
||||
0,0,2,2,2,2,0,0
|
||||
))
|
||||
vcard.sprites[3].setAll(intArrayOf(
|
||||
2,1,2,2,2,0,0,0,
|
||||
1,1,2,2,2,2,0,0,
|
||||
1,3,1,2,3,3,0,0,
|
||||
1,1,1,3,3,3,0,0,
|
||||
1,1,1,1,3,3,0,0,
|
||||
0,1,1,1,0,0,0,0,
|
||||
0,0,2,2,2,0,0,0,
|
||||
0,0,2,2,2,2,0,0
|
||||
))*/
|
||||
}
|
||||
|
||||
var angle = 0.0
|
||||
|
||||
override fun update(container: GameContainer, game: StateBasedGame?, delta: Int) {
|
||||
Terrarum.delta = delta
|
||||
|
||||
Terrarum.appgc.setTitle("VT — F: ${container.fps}" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M" +
|
||||
" ${Random().nextInt(100)}")
|
||||
monitor.update(container, delta)
|
||||
computer.update(container, delta)
|
||||
|
||||
|
||||
/*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram
|
||||
val sprites = vcard.sprites
|
||||
angle += delta / 1000.0
|
||||
|
||||
|
||||
sprites[0].posX = (Math.cos(angle) * 80 + 100).roundInt() - 16
|
||||
sprites[0].posY = (Math.sin(angle) * 0 + 100).roundInt() - 8
|
||||
|
||||
sprites[1].posX = (Math.cos(angle) * 80 + 100).roundInt()
|
||||
sprites[1].posY = (Math.sin(angle) * 0 + 100).roundInt() - 8
|
||||
|
||||
sprites[2].posX = (Math.cos(angle) * 80 + 100).roundInt() - 16
|
||||
sprites[2].posY = (Math.sin(angle) * 0 + 100).roundInt()
|
||||
|
||||
sprites[3].posX = (Math.cos(angle) * 80 + 100).roundInt()
|
||||
sprites[3].posY = (Math.sin(angle) * 0 + 100).roundInt()*/
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_TTY
|
||||
|
||||
|
||||
override fun render(container: GameContainer, game: StateBasedGame?, g: Graphics) {
|
||||
monitor.render(container, monitorUIG)
|
||||
g.drawImage(monitorUI, 30f, 30f)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
monitor.keyPressed(key, c)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Screen
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
|
||||
import net.torvald.dataclass.CircularArray
|
||||
import net.torvald.imagefont.GameFontBase
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum.HALFH
|
||||
import net.torvald.terrarum.Terrarum.HALFW
|
||||
import net.torvald.terrarum.Terrarum.delta
|
||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
import net.torvald.terrarum.blockstats.BlockStats
|
||||
import net.torvald.terrarum.concurrent.ThreadParallel
|
||||
import net.torvald.terrarum.console.*
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameactors.physicssolver.CollisionSolver
|
||||
import net.torvald.terrarum.gamecontroller.GameController
|
||||
@@ -16,30 +18,33 @@ import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.WorldSimulator
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer.constructRGBFromInt
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarum.worldgenerator.WorldGenerator
|
||||
import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser
|
||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
import net.torvald.terrarum.blockstats.BlockStats
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.util.*
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.concurrent.locks.Lock
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
|
||||
import javax.swing.JOptionPane
|
||||
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.ui.*
|
||||
import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser
|
||||
import net.torvald.terrarum.worldgenerator.WorldGenerator
|
||||
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-30.
|
||||
* Created by minjaesong on 2017-06-16.
|
||||
*/
|
||||
class StateInGame : BasicGameState() {
|
||||
|
||||
class StateInGameGDX(val batch: SpriteBatch) : Screen {
|
||||
|
||||
|
||||
private val ACTOR_UPDATE_RANGE = 4096
|
||||
|
||||
lateinit var world: GameWorld
|
||||
@@ -48,7 +53,7 @@ class StateInGame : BasicGameState() {
|
||||
* list of Actors that is sorted by Actors' referenceID
|
||||
*/
|
||||
val ACTORCONTAINER_INITIAL_SIZE = 64
|
||||
val PARTICLES_MAX = Terrarum.getConfigInt("maxparticles")
|
||||
val PARTICLES_MAX = TerrarumGDX.getConfigInt("maxparticles")
|
||||
val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
val actorContainerInactive = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
val particlesContainer = CircularArray<ParticleBase>(PARTICLES_MAX)
|
||||
@@ -68,10 +73,8 @@ class StateInGame : BasicGameState() {
|
||||
val ZOOM_MAX = 4.0f
|
||||
val ZOOM_MIN = 0.5f
|
||||
|
||||
val worldDrawFrameBuffer = Image(Terrarum.WIDTH.div(ZOOM_MIN).ceilInt(), Terrarum.HEIGHT.div(ZOOM_MIN).ceilInt())
|
||||
val worldG = worldDrawFrameBuffer.graphics
|
||||
val backDrawFrameBuffer = Image(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||
val backG = backDrawFrameBuffer.graphics
|
||||
var worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
|
||||
var backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false)
|
||||
|
||||
//private lateinit var shader12BitCol: Shader // grab LibGDX if you want some shader
|
||||
//private lateinit var shaderBlur: Shader
|
||||
@@ -114,13 +117,70 @@ class StateInGame : BasicGameState() {
|
||||
inline val canPlayerControl: Boolean
|
||||
get() = !paused // FIXME temporary behab (block movement if the game is paused or paused by UIs)
|
||||
|
||||
@Throws(SlickException::class)
|
||||
override fun init(gameContainer: GameContainer, stateBasedGame: StateBasedGame) {
|
||||
// state init code. Executed before the game goes into any "state" in states in StateBasedGame.java
|
||||
var particlesActive = 0
|
||||
private set
|
||||
|
||||
|
||||
//////////////
|
||||
// GDX code //
|
||||
//////////////
|
||||
|
||||
var camera = OrthographicCamera(Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
|
||||
|
||||
// invert Y
|
||||
fun initViewPort(width: Int, height: Int, aspect: Float) {
|
||||
val width = width.toFloat()
|
||||
val height = height.toFloat()
|
||||
|
||||
// Get the window size in pixels
|
||||
val w = Gdx.graphics.width.toFloat()
|
||||
val h = Gdx.graphics.height.toFloat()
|
||||
|
||||
val vw: Float
|
||||
val vh: Float // Viewport size in screen coordinates
|
||||
val ox: Float
|
||||
val oy: Float // Viewport offset in screen coordinates
|
||||
|
||||
// Check aspect ratio
|
||||
if (w > h * aspect) {
|
||||
// Black bars on the sides
|
||||
vh = h
|
||||
vw = Math.round(vh * aspect).toFloat()
|
||||
oy = 0f
|
||||
ox = (w - vw) / 2
|
||||
}
|
||||
else {
|
||||
// Black bars on top and bottom
|
||||
vw = w
|
||||
vh = Math.round(vw * (1 / aspect)).toFloat()
|
||||
ox = 0f
|
||||
oy = (h - vh) / 2
|
||||
}
|
||||
|
||||
// Create camera with the desired resolution
|
||||
camera = OrthographicCamera(width, height)
|
||||
|
||||
// Move camera center to push 0,0 into the corner
|
||||
camera.translate(width / 2, height / 2)
|
||||
|
||||
// Set Y to point downwards
|
||||
camera.setToOrtho(true, width, height)
|
||||
|
||||
// Update camera matrix
|
||||
camera.update()
|
||||
|
||||
// Set viewport to restrict drawing
|
||||
Gdx.gl20.glViewport(ox.toInt(), oy.toInt(), vw.toInt(), vh.toInt())
|
||||
}
|
||||
|
||||
override fun enter(gc: GameContainer, sbg: StateBasedGame) {
|
||||
|
||||
override fun show() {
|
||||
// Set up viewport on first load
|
||||
initViewPort(Gdx.graphics.width, Gdx.graphics.height, Gdx.graphics.width.toFloat() / Gdx.graphics.height.toFloat())
|
||||
}
|
||||
|
||||
|
||||
fun enter() {
|
||||
// load things when the game entered this "state"
|
||||
// load necessary shaders
|
||||
//shader12BitCol = Shader.makeShader("./assets/4096.vert", "./assets/4096.frag")
|
||||
@@ -163,10 +223,10 @@ class StateInGame : BasicGameState() {
|
||||
notifier = UIHandler(Notification())
|
||||
notifier.UI.handler = notifier
|
||||
notifier.setPosition(
|
||||
(Terrarum.WIDTH - notifier.UI.width) / 2, Terrarum.HEIGHT - notifier.UI.height)
|
||||
(Gdx.graphics.width - notifier.UI.width) / 2, Gdx.graphics.height - notifier.UI.height)
|
||||
|
||||
// set smooth lighting as in config
|
||||
KeyToggler.forceSet(KEY_LIGHTMAP_SMOOTH, Terrarum.getConfigBoolean("smoothlighting"))
|
||||
KeyToggler.forceSet(KEY_LIGHTMAP_SMOOTH, TerrarumGDX.getConfigBoolean("smoothlighting"))
|
||||
|
||||
|
||||
|
||||
@@ -175,10 +235,10 @@ class StateInGame : BasicGameState() {
|
||||
uiInventoryPlayer = UIHandler(
|
||||
UIInventory(player,
|
||||
width = 840,
|
||||
height = Terrarum.HEIGHT - 160,
|
||||
height = Gdx.graphics.height - 160,
|
||||
categoryWidth = 210
|
||||
),
|
||||
toggleKey = Terrarum.getConfigInt("keyinventory")
|
||||
toggleKey = TerrarumGDX.getConfigInt("keyinventory")
|
||||
)
|
||||
uiInventoryPlayer.setPosition(
|
||||
-uiInventoryPlayer.UI.width,
|
||||
@@ -193,34 +253,34 @@ class StateInGame : BasicGameState() {
|
||||
|
||||
// pie menu
|
||||
uiPieMenu = UIHandler(UIPieMenu())
|
||||
uiPieMenu.setPosition(HALFW, HALFH)
|
||||
uiPieMenu.setPosition(TerrarumGDX.HALFW, TerrarumGDX.HALFH)
|
||||
|
||||
// vital metre
|
||||
// fill in getter functions by
|
||||
// (uiAliases[UI_QUICK_BAR]!!.UI as UIVitalMetre).vitalGetterMax = { some_function }
|
||||
uiVitalPrimary = UIHandler(UIVitalMetre(player, { 80f }, { 100f }, Color.red, 2), customPositioning = true)
|
||||
uiVitalPrimary.setAsAlwaysVisible()
|
||||
uiVitalSecondary = UIHandler(UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1), customPositioning = true)
|
||||
uiVitalSecondary.setAsAlwaysVisible()
|
||||
uiVitalItem = UIHandler(UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0), customPositioning = true)
|
||||
uiVitalItem.setAsAlwaysVisible()
|
||||
//uiVitalPrimary = UIHandler(UIVitalMetre(player, { 80f }, { 100f }, Color.red, 2), customPositioning = true)
|
||||
//uiVitalPrimary.setAsAlwaysVisible()
|
||||
//uiVitalSecondary = UIHandler(UIVitalMetre(player, { 73f }, { 100f }, Color(0x00dfff), 1), customPositioning = true)
|
||||
//uiVitalSecondary.setAsAlwaysVisible()
|
||||
//uiVitalItem = UIHandler(UIVitalMetre(player, { null }, { null }, Color(0xffcc00), 0), customPositioning = true)
|
||||
//uiVitalItem.setAsAlwaysVisible()
|
||||
|
||||
// basic watch-style notification bar (temperature, new mail)
|
||||
uiWatchBasic = UIHandler(UIBasicNotifier(player))
|
||||
uiWatchBasic.setAsAlwaysVisible()
|
||||
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.UI.width, 0)
|
||||
uiWatchBasic.setPosition(Gdx.graphics.width - uiWatchBasic.UI.width, 0)
|
||||
|
||||
uiWatchTierOne = UIHandler(UITierOneWatch(player))
|
||||
uiWatchTierOne.setAsAlwaysVisible()
|
||||
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2)
|
||||
uiWatchTierOne.setPosition(Gdx.graphics.width - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2)
|
||||
|
||||
|
||||
// batch-process uiAliases
|
||||
uiAliases = arrayListOf(
|
||||
// drawn first
|
||||
uiVitalPrimary,
|
||||
uiVitalSecondary,
|
||||
uiVitalItem,
|
||||
//uiVitalPrimary,
|
||||
//uiVitalSecondary,
|
||||
//uiVitalItem,
|
||||
uiPieMenu,
|
||||
uiQuickBar,
|
||||
uiWatchBasic,
|
||||
@@ -234,27 +294,26 @@ class StateInGame : BasicGameState() {
|
||||
)
|
||||
uiAlasesPausing.forEach { addUI(it) } // put them all to the UIContainer
|
||||
uiAliases.forEach { addUI(it) } // put them all to the UIContainer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// audio test
|
||||
//AudioResourceLibrary.ambientsWoods[0].play()
|
||||
}
|
||||
|
||||
var particlesActive = 0
|
||||
private set
|
||||
|
||||
override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) {
|
||||
///////////////
|
||||
// prod code //
|
||||
///////////////
|
||||
override fun render(delta: Float) {
|
||||
Gdx.graphics.setTitle(GAME_NAME +
|
||||
" — F: ${Gdx.graphics.framesPerSecond} (${TerrarumGDX.TARGET_INTERNAL_FPS})" +
|
||||
" — M: ${TerrarumGDX.memInUse}M / ${TerrarumGDX.memTotal}M / ${TerrarumGDX.memXmx}M"
|
||||
)
|
||||
|
||||
|
||||
/** UPDATE CODE GOES HERE */
|
||||
|
||||
particlesActive = 0
|
||||
Terrarum.delta = delta
|
||||
setAppTitle()
|
||||
|
||||
|
||||
KeyToggler.update(gc.input)
|
||||
GameController.processInput(gc, delta, gc.input)
|
||||
KeyToggler.update()
|
||||
GameController.processInput(delta)
|
||||
|
||||
|
||||
if (!paused) {
|
||||
@@ -265,26 +324,22 @@ class StateInGame : BasicGameState() {
|
||||
BlockPropUtil.dynamicLumFuncTickClock()
|
||||
world.updateWorldTime(delta)
|
||||
//WorldSimulator(player, delta)
|
||||
WeatherMixer.update(gc, delta)
|
||||
WeatherMixer.update(delta)
|
||||
BlockStats.update()
|
||||
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
|
||||
world.globalLight = constructRGBFromInt(
|
||||
WeatherMixer.globalLightNow.redByte,
|
||||
WeatherMixer.globalLightNow.greenByte,
|
||||
WeatherMixer.globalLightNow.blueByte
|
||||
)
|
||||
world.globalLight = WeatherMixer.globalLightNow.toRGB10()
|
||||
|
||||
|
||||
///////////////////////////
|
||||
// input-related updates //
|
||||
///////////////////////////
|
||||
uiContainer.forEach { it.processInput(gc, delta, gc.input) }
|
||||
uiContainer.forEach { it.processInput(delta) }
|
||||
|
||||
|
||||
////////////////////////////
|
||||
// camera-related updates //
|
||||
////////////////////////////
|
||||
FeaturesDrawer.update(gc, delta)
|
||||
FeaturesDrawer.update(delta)
|
||||
WorldCamera.update()
|
||||
|
||||
|
||||
@@ -298,8 +353,8 @@ class StateInGame : BasicGameState() {
|
||||
wakeDormantActors()
|
||||
// determine whether the actor should keep being activated or be dormant
|
||||
KillOrKnockdownActors()
|
||||
updateActors(gc, delta)
|
||||
particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(gc, delta) }
|
||||
updateActors(delta)
|
||||
particlesContainer.forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) }
|
||||
// TODO thread pool(?)
|
||||
CollisionSolver.process()
|
||||
}
|
||||
@@ -308,9 +363,9 @@ class StateInGame : BasicGameState() {
|
||||
////////////////////////
|
||||
// ui-related updates //
|
||||
////////////////////////
|
||||
uiContainer.forEach { it.update(gc, delta) }
|
||||
debugWindow.update(gc, delta)
|
||||
notifier.update(gc, delta)
|
||||
uiContainer.forEach { it.update(delta) }
|
||||
debugWindow.update(delta)
|
||||
notifier.update(delta)
|
||||
|
||||
// update debuggers using javax.swing //
|
||||
if (Authenticator.b()) {
|
||||
@@ -325,9 +380,183 @@ class StateInGame : BasicGameState() {
|
||||
/////////////////////////
|
||||
|
||||
// determine if lightmap blending should be done
|
||||
Terrarum.setConfig("smoothlighting", KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH))
|
||||
TerrarumGDX.setConfig("smoothlighting", KeyToggler.isOn(KEY_LIGHTMAP_SMOOTH))
|
||||
|
||||
|
||||
|
||||
/** RENDER CODE GOES HERE */
|
||||
renderGame(batch, delta)
|
||||
}
|
||||
|
||||
|
||||
private fun renderGame(batch: SpriteBatch, delta: Float) {
|
||||
Gdx.gl.glClearColor(.157f, .157f, .157f, 0f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
camera.position.set(-WorldCamera.x.toFloat(), -WorldCamera.y.toFloat(), 0f) // make camara work
|
||||
|
||||
batch.projectionMatrix = camera.combined
|
||||
|
||||
TerrarumGDX.GLOBAL_RENDER_TIMER += 1
|
||||
|
||||
|
||||
// clean the shit beforehand
|
||||
worldDrawFrameBuffer.inAction {
|
||||
Gdx.gl.glClearColor(0f,0f,0f,1f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
}
|
||||
backDrawFrameBuffer.inAction {
|
||||
Gdx.gl.glClearColor(0f,0f,0f,1f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
blendNormal()
|
||||
backDrawFrameBuffer.inAction {
|
||||
batch.inUse {
|
||||
WeatherMixer.render(batch) // drawing to gwin so that any lights from lamp wont "leak" to the skybox
|
||||
// e.g. Bright blue light on sunset
|
||||
}
|
||||
}
|
||||
blendNormal()
|
||||
|
||||
/////////////////////////////
|
||||
// draw map related stuffs //
|
||||
/////////////////////////////
|
||||
worldDrawFrameBuffer.inAction {
|
||||
batch.inUse {
|
||||
BlocksDrawer.renderWall(batch)
|
||||
actorsRenderBehind.forEach { it.drawBody(batch) }
|
||||
actorsRenderBehind.forEach { it.drawGlow(batch) }
|
||||
particlesContainer.forEach { it.drawBody(batch) }
|
||||
particlesContainer.forEach { it.drawGlow(batch) }
|
||||
BlocksDrawer.renderTerrain(batch)
|
||||
|
||||
/////////////////
|
||||
// draw actors //
|
||||
/////////////////
|
||||
actorsRenderMiddle.forEach { it.drawBody(batch) }
|
||||
actorsRenderMidTop.forEach { it.drawBody(batch) }
|
||||
player?.drawBody(batch)
|
||||
actorsRenderFront.forEach { it.drawBody(batch) }
|
||||
// --> Change of blend mode <-- introduced by childs of ActorWithBody //
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// draw map related stuffs //
|
||||
/////////////////////////////
|
||||
LightmapRenderer.renderLightMap()
|
||||
|
||||
BlocksDrawer.renderFront(batch, false)
|
||||
// --> blendNormal() <-- by BlocksDrawer.renderFront
|
||||
FeaturesDrawer.render(batch)
|
||||
|
||||
|
||||
FeaturesDrawer.drawEnvOverlay(batch)
|
||||
|
||||
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul()
|
||||
else blendNormal()
|
||||
LightmapRenderer.draw(batch)
|
||||
|
||||
|
||||
//////////////////////
|
||||
// draw actor glows //
|
||||
//////////////////////
|
||||
actorsRenderMiddle.forEach { it.drawGlow(batch) }
|
||||
actorsRenderMidTop.forEach { it.drawGlow(batch) }
|
||||
player?.drawGlow(batch)
|
||||
actorsRenderFront.forEach { it.drawGlow(batch) }
|
||||
// --> blendLightenOnly() <-- introduced by childs of ActorWithBody //
|
||||
|
||||
|
||||
////////////////////////
|
||||
// debug informations //
|
||||
////////////////////////
|
||||
blendNormal()
|
||||
// draw reference ID if debugWindow is open
|
||||
if (debugWindow.isVisible) {
|
||||
actorContainer.forEachIndexed { i, actor ->
|
||||
if (actor is ActorWithBody) {
|
||||
batch.color = Color.WHITE
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch,
|
||||
actor.referenceID.toString(),
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.canonicalY.toFloat() + 4
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// debug physics
|
||||
if (KeyToggler.isOn(Key.F11)) {
|
||||
actorContainer.forEachIndexed { i, actor ->
|
||||
if (actor is ActorWithPhysics) {
|
||||
/*shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) {
|
||||
shapeRenderer.color = Color(1f, 0f, 1f, 1f)
|
||||
//shapeRenderer.lineWidth = 1f
|
||||
shapeRenderer.rect(
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.startY.toFloat(),
|
||||
actor.hitbox.width.toFloat(),
|
||||
actor.hitbox.height.toFloat()
|
||||
)
|
||||
}*/
|
||||
|
||||
// velocity
|
||||
batch.color = Color.CHARTREUSE//GameFontBase.codeToCol["g"]
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch,
|
||||
"${0x7F.toChar()}X ${actor.externalForce.x}",
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.canonicalY.toFloat() + 4 + 8
|
||||
)
|
||||
TerrarumGDX.fontSmallNumbers.draw(batch,
|
||||
"${0x7F.toChar()}Y ${actor.externalForce.y}",
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.canonicalY.toFloat() + 4 + 8 * 2
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// fluidmap debug
|
||||
if (KeyToggler.isOn(Key.F4))
|
||||
WorldSimulator.drawFluidMapDebug(batch)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/////////////////
|
||||
// GUI Predraw //
|
||||
/////////////////
|
||||
//worldG.flush()
|
||||
//backG.drawImage(worldDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f)
|
||||
//backG.flush()
|
||||
|
||||
|
||||
/////////////////////
|
||||
// draw UIs ONLY! //
|
||||
/////////////////////
|
||||
uiContainer.forEach { if (it != consoleHandler) it.render(batch) }
|
||||
debugWindow.render(batch)
|
||||
// make sure console draws on top of other UIs
|
||||
consoleHandler.render(batch)
|
||||
notifier.render(batch)
|
||||
|
||||
|
||||
//////////////////
|
||||
// GUI Postdraw //
|
||||
//////////////////
|
||||
//backG.flush()
|
||||
//gwin.drawImage(backDrawFrameBuffer, 0f, 0f)
|
||||
|
||||
// centre marker
|
||||
/*gwin.color = Color(0x00FFFF)
|
||||
gwin.lineWidth = 1f
|
||||
gwin.drawLine(Gdx.graphics.width / 2f, 0f, Gdx.graphics.width / 2f, Gdx.graphics.height.toFloat())
|
||||
gwin.drawLine(0f, Gdx.graphics.height / 2f, Gdx.graphics.width.toFloat(), Gdx.graphics.height / 2f)*/
|
||||
}
|
||||
|
||||
|
||||
private fun repossessActor() {
|
||||
// check if currently pocessed actor is removed from game
|
||||
if (!theGameHasActor(player)) {
|
||||
@@ -345,7 +574,7 @@ class StateInGame : BasicGameState() {
|
||||
}
|
||||
|
||||
playableActorDelegate = newActor
|
||||
WorldSimulator(player, delta)
|
||||
WorldSimulator(player, Gdx.graphics.deltaTime)
|
||||
}
|
||||
|
||||
private fun changePossession(refid: Int) {
|
||||
@@ -360,192 +589,9 @@ class StateInGame : BasicGameState() {
|
||||
// accept new delegate
|
||||
playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid)
|
||||
playableActorDelegate!!.actor.collisionType = ActorWithPhysics.COLLISION_KINEMATIC
|
||||
WorldSimulator(player, delta)
|
||||
WorldSimulator(player, Gdx.graphics.deltaTime)
|
||||
}
|
||||
|
||||
private fun setAppTitle() {
|
||||
Terrarum.appgc.setTitle(
|
||||
Terrarum.NAME +
|
||||
" — F: ${Terrarum.appgc.fps} (${Terrarum.TARGET_INTERNAL_FPS})" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
|
||||
)
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, sbg: StateBasedGame, gwin: Graphics) {
|
||||
Terrarum.GLOBAL_RENDER_TIMER += 1
|
||||
|
||||
// clean the shit beforehand
|
||||
worldG.clear()
|
||||
backG.clear()
|
||||
|
||||
blendNormal()
|
||||
|
||||
|
||||
drawSkybox(backG) // drawing to gwin so that any lights from lamp wont "leak" to the skybox
|
||||
// e.g. Bright blue light on sunset
|
||||
|
||||
|
||||
// make camara work
|
||||
worldG.translate(-WorldCamera.x.toFloat(), -WorldCamera.y.toFloat())
|
||||
|
||||
|
||||
blendNormal()
|
||||
|
||||
/////////////////////////////
|
||||
// draw map related stuffs //
|
||||
/////////////////////////////
|
||||
BlocksDrawer.renderWall(worldG)
|
||||
actorsRenderBehind.forEach { it.drawBody(worldG) }
|
||||
actorsRenderBehind.forEach { it.drawGlow(worldG) }
|
||||
particlesContainer.forEach { it.drawBody(worldG) }
|
||||
particlesContainer.forEach { it.drawGlow(worldG) }
|
||||
BlocksDrawer.renderTerrain(worldG)
|
||||
|
||||
/////////////////
|
||||
// draw actors //
|
||||
/////////////////
|
||||
actorsRenderMiddle.forEach { it.drawBody(worldG) }
|
||||
actorsRenderMidTop.forEach { it.drawBody(worldG) }
|
||||
player?.drawBody(worldG)
|
||||
actorsRenderFront.forEach { it.drawBody(worldG) }
|
||||
// --> Change of blend mode <-- introduced by childs of ActorWithBody //
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// draw map related stuffs //
|
||||
/////////////////////////////
|
||||
LightmapRenderer.renderLightMap()
|
||||
|
||||
BlocksDrawer.renderFront(worldG, false)
|
||||
// --> blendNormal() <-- by BlocksDrawer.renderFront
|
||||
FeaturesDrawer.render(gc, worldG)
|
||||
|
||||
|
||||
FeaturesDrawer.drawEnvOverlay(worldG)
|
||||
|
||||
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul()
|
||||
else blendNormal()
|
||||
LightmapRenderer.draw(worldG)
|
||||
|
||||
|
||||
//////////////////////
|
||||
// draw actor glows //
|
||||
//////////////////////
|
||||
actorsRenderMiddle.forEach { it.drawGlow(worldG) }
|
||||
actorsRenderMidTop.forEach { it.drawGlow(worldG) }
|
||||
player?.drawGlow(worldG)
|
||||
actorsRenderFront.forEach { it.drawGlow(worldG) }
|
||||
// --> blendLightenOnly() <-- introduced by childs of ActorWithBody //
|
||||
|
||||
|
||||
////////////////////////
|
||||
// debug informations //
|
||||
////////////////////////
|
||||
blendNormal()
|
||||
// draw reference ID if debugWindow is open
|
||||
if (debugWindow.isVisible) {
|
||||
actorContainer.forEachIndexed { i, actor ->
|
||||
if (actor is ActorWithBody) {
|
||||
worldG.color = Color.white
|
||||
worldG.font = Terrarum.fontSmallNumbers
|
||||
worldG.drawString(
|
||||
actor.referenceID.toString(),
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.canonicalY.toFloat() + 4
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// debug physics
|
||||
if (KeyToggler.isOn(Key.F11)) {
|
||||
actorContainer.forEachIndexed { i, actor ->
|
||||
if (actor is ActorWithPhysics) {
|
||||
worldG.color = Color(1f, 0f, 1f, 1f)
|
||||
worldG.font = Terrarum.fontSmallNumbers
|
||||
worldG.lineWidth = 1f
|
||||
worldG.drawRect(
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.startY.toFloat(),
|
||||
actor.hitbox.width.toFloat(),
|
||||
actor.hitbox.height.toFloat()
|
||||
)
|
||||
|
||||
// velocity
|
||||
worldG.color = GameFontBase.codeToCol["g"]
|
||||
worldG.drawString(
|
||||
"${0x7F.toChar()}X ${actor.externalForce.x}",
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.canonicalY.toFloat() + 4 + 8
|
||||
)
|
||||
worldG.drawString(
|
||||
"${0x7F.toChar()}Y ${actor.externalForce.y}",
|
||||
actor.hitbox.startX.toFloat(),
|
||||
actor.hitbox.canonicalY.toFloat() + 4 + 8 * 2
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// fluidmap debug
|
||||
if (KeyToggler.isOn(Key.F4))
|
||||
WorldSimulator.drawFluidMapDebug(worldG)
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////
|
||||
// GUI Predraw //
|
||||
/////////////////
|
||||
worldG.flush()
|
||||
backG.drawImage(worldDrawFrameBuffer.getScaledCopy(screenZoom), 0f, 0f)
|
||||
backG.flush()
|
||||
|
||||
|
||||
/////////////////////
|
||||
// draw UIs ONLY! //
|
||||
/////////////////////
|
||||
uiContainer.forEach { if (it != consoleHandler) it.render(gc, sbg, backG) }
|
||||
debugWindow.render(gc, sbg, backG)
|
||||
// make sure console draws on top of other UIs
|
||||
consoleHandler.render(gc, sbg, backG)
|
||||
notifier.render(gc, sbg, backG)
|
||||
|
||||
|
||||
//////////////////
|
||||
// GUI Postdraw //
|
||||
//////////////////
|
||||
backG.flush()
|
||||
gwin.drawImage(backDrawFrameBuffer, 0f, 0f)
|
||||
|
||||
// centre marker
|
||||
/*gwin.color = Color(0x00FFFF)
|
||||
gwin.lineWidth = 1f
|
||||
gwin.drawLine(Terrarum.WIDTH / 2f, 0f, Terrarum.WIDTH / 2f, Terrarum.HEIGHT.toFloat())
|
||||
gwin.drawLine(0f, Terrarum.HEIGHT / 2f, Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT / 2f)*/
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
if (key == Key.GRAVE || key == Key.ESCAPE) {
|
||||
consoleHandler.toggleOpening()
|
||||
}
|
||||
else if (key == Key.F3) {
|
||||
debugWindow.toggleOpening()
|
||||
}
|
||||
|
||||
GameController.keyPressed(key, c)
|
||||
}
|
||||
override fun keyReleased(key: Int, c: Char) { GameController.keyReleased(key, c) }
|
||||
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) { GameController.mouseMoved(oldx, oldy, newx, newy) }
|
||||
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) { GameController.mouseDragged(oldx, oldy, newx, newy) }
|
||||
override fun mousePressed(button: Int, x: Int, y: Int) { GameController.mousePressed(button, x, y) }
|
||||
override fun mouseReleased(button: Int, x: Int, y: Int) { GameController.mouseReleased(button, x, y) }
|
||||
override fun mouseWheelMoved(change: Int) { GameController.mouseWheelMoved(change) }
|
||||
override fun controllerButtonPressed(controller: Int, button: Int) { GameController.controllerButtonPressed(controller, button) }
|
||||
override fun controllerButtonReleased(controller: Int, button: Int) { GameController.controllerButtonReleased(controller, button) }
|
||||
|
||||
override fun getID(): Int = Terrarum.STATE_ID_GAME
|
||||
|
||||
private fun drawSkybox(g: Graphics) = WeatherMixer.render(g)
|
||||
|
||||
/** Send message to notifier UI and toggle the UI as opened. */
|
||||
fun sendNotification(msg: Array<String>) {
|
||||
(notifier.UI as Notification).sendNotification(msg)
|
||||
@@ -600,17 +646,16 @@ class StateInGame : BasicGameState() {
|
||||
*
|
||||
* NOTE: concurrency for actor updating is currently disabled because of it's poor performance
|
||||
*/
|
||||
fun updateActors(gc: GameContainer, delta: Int) {
|
||||
if (false) { // don't multithread this for now, it's SLOWER //if (Terrarum.MULTITHREAD && actorContainer.size > Terrarum.THREADS) {
|
||||
fun updateActors(delta: Float) {
|
||||
if (false) { // don't multithread this for now, it's SLOWER //if (TerrarumGDX.MULTITHREAD && actorContainer.size > TerrarumGDX.THREADS) {
|
||||
val actors = actorContainer.size.toFloat()
|
||||
// set up indices
|
||||
for (i in 0..Terrarum.THREADS - 1) {
|
||||
for (i in 0..TerrarumGDX.THREADS - 1) {
|
||||
ThreadParallel.map(
|
||||
i,
|
||||
ThreadActorUpdate(
|
||||
actors.div(Terrarum.THREADS).times(i).roundInt(),
|
||||
actors.div(Terrarum.THREADS).times(i.plus(1)).roundInt() - 1,
|
||||
gc, delta
|
||||
actors.div(TerrarumGDX.THREADS).times(i).roundInt(),
|
||||
actors.div(TerrarumGDX.THREADS).times(i.plus(1)).roundInt() - 1
|
||||
),
|
||||
"ActorUpdate"
|
||||
)
|
||||
@@ -620,18 +665,18 @@ class StateInGame : BasicGameState() {
|
||||
}
|
||||
else {
|
||||
actorContainer.forEach {
|
||||
it.update(gc, delta)
|
||||
it.update(delta)
|
||||
|
||||
if (it is Pocketed) {
|
||||
it.inventory.forEach { inventoryEntry ->
|
||||
inventoryEntry.item.effectWhileInPocket(gc, delta)
|
||||
inventoryEntry.item.effectWhileInPocket(delta)
|
||||
if (it.equipped(inventoryEntry.item)) {
|
||||
inventoryEntry.item.effectWhenEquipped(gc, delta)
|
||||
inventoryEntry.item.effectWhenEquipped(delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre)
|
||||
//AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,26 +691,26 @@ class StateInGame : BasicGameState() {
|
||||
min(// take min of normal position and wrapped (x < 0) position
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() +
|
||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX + world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX + world.width * FeaturesDrawer.TILE_SIZE).sqr() +
|
||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX - world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX - world.width * FeaturesDrawer.TILE_SIZE).sqr() +
|
||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr()
|
||||
)
|
||||
private fun distToCameraSqr(a: ActorWithBody) =
|
||||
min(
|
||||
(a.hitbox.startX - WorldCamera.x).sqr() +
|
||||
(a.hitbox.startY - WorldCamera.y).sqr(),
|
||||
(a.hitbox.startX - WorldCamera.x + world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.startX - WorldCamera.x + world.width * FeaturesDrawer.TILE_SIZE).sqr() +
|
||||
(a.hitbox.startY - WorldCamera.y).sqr(),
|
||||
(a.hitbox.startX - WorldCamera.x - world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.startX - WorldCamera.x - world.width * FeaturesDrawer.TILE_SIZE).sqr() +
|
||||
(a.hitbox.startY - WorldCamera.y).sqr()
|
||||
)
|
||||
|
||||
/** whether the actor is within screen */
|
||||
private fun ActorWithBody.inScreen() =
|
||||
distToCameraSqr(this) <=
|
||||
(Terrarum.WIDTH.plus(this.hitbox.width.div(2)).times(1 / Terrarum.ingame!!.screenZoom).sqr() +
|
||||
Terrarum.HEIGHT.plus(this.hitbox.height.div(2)).times(1 / Terrarum.ingame!!.screenZoom).sqr())
|
||||
(Gdx.graphics.width.plus(this.hitbox.width.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr() +
|
||||
Gdx.graphics.height.plus(this.hitbox.height.div(2)).times(1 / TerrarumGDX.ingame!!.screenZoom).sqr())
|
||||
|
||||
|
||||
/** whether the actor is within update range */
|
||||
@@ -879,4 +924,29 @@ class StateInGame : BasicGameState() {
|
||||
lock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
// TODO no pause when off-focus on desktop
|
||||
}
|
||||
|
||||
override fun resume() {
|
||||
}
|
||||
|
||||
override fun hide() {
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
worldDrawFrameBuffer.dispose()
|
||||
worldDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width.div(ZOOM_MIN).ceilInt(), Gdx.graphics.height.div(ZOOM_MIN).ceilInt(), false)
|
||||
backDrawFrameBuffer.dispose()
|
||||
backDrawFrameBuffer = FrameBuffer(Pixmap.Format.RGBA8888, Gdx.graphics.width, Gdx.graphics.height, false)
|
||||
|
||||
// Set up viewport when window is resized
|
||||
initViewPort(width, height, width.toFloat() / height.toFloat())
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
worldDrawFrameBuffer.dispose()
|
||||
backDrawFrameBuffer.dispose()
|
||||
}
|
||||
}
|
||||
@@ -1,323 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.Terrarum.STATE_ID_TEST_INPUT
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gameworld.toUint
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.ALException
|
||||
import org.lwjgl.BufferUtils
|
||||
import org.lwjgl.openal.AL
|
||||
import org.lwjgl.openal.AL10
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.ArrayList
|
||||
import javax.sound.midi.*
|
||||
import kotlin.experimental.and
|
||||
|
||||
/**
|
||||
* Midi input test for Spieluhr (this game's version of Note Block)
|
||||
*
|
||||
* Spieluhrs can make sound ranged from C1 to C6
|
||||
* (61 keys, which is the most common Midi Keyboard configuration)
|
||||
*
|
||||
* There is some latency if you are on Windows. Mac and Linux should be okay
|
||||
* because real musicians use Mac anyway, for a reason.
|
||||
*
|
||||
* Created by SKYHi14 on 2017-03-17.
|
||||
*/
|
||||
class StateMidiInputTest : BasicGameState() {
|
||||
|
||||
var midiKeyboard: MidiDevice? = null
|
||||
val beeperSlave = BeeperSlave()
|
||||
|
||||
val preferredDeviceList = arrayOf(
|
||||
"USB MIDI"
|
||||
)
|
||||
val avoidedDeviceList = arrayOf(
|
||||
"Real Time Sequencer"
|
||||
)
|
||||
|
||||
init {
|
||||
val midiDevInfo = MidiSystem.getMidiDeviceInfo()
|
||||
|
||||
midiDevInfo.forEach {
|
||||
//println(it)
|
||||
|
||||
val device = MidiSystem.getMidiDevice(it)
|
||||
try {
|
||||
if (!avoidedDeviceList.contains(device.deviceInfo.name)) {
|
||||
device.transmitter // test if tranmitter available
|
||||
//println("Transmitter: $it")
|
||||
|
||||
midiKeyboard = device
|
||||
}
|
||||
}
|
||||
catch (e: MidiUnavailableException) {
|
||||
//println("(no transmitter found)")
|
||||
}
|
||||
|
||||
//println()
|
||||
}
|
||||
|
||||
//midiKeyboard = MidiSystem.getMidiDevice()
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
if (midiKeyboard != null) {
|
||||
midiKeyboard!!.open()
|
||||
midiKeyboard!!.transmitter.receiver = MidiInputReceiver(beeperSlave)
|
||||
println("Opened Midi device ${midiKeyboard!!.deviceInfo.name}")
|
||||
}
|
||||
else {
|
||||
println("Midi keyboard not found, using computer keyboard as a controller.")
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
|
||||
beeperSlave.runBeepQueueManager(delta)
|
||||
}
|
||||
|
||||
override fun getID() = STATE_ID_TEST_INPUT
|
||||
|
||||
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
g.font = Terrarum.fontGame
|
||||
g.drawString("Listening from ${midiKeyboard!!.deviceInfo.name}", 10f, 10f)
|
||||
}
|
||||
|
||||
|
||||
class MidiInputReceiver(val slave: BeeperSlave) : Receiver {
|
||||
override fun send(message: MidiMessage, timeStamp: Long) {
|
||||
//println("MIDI Event ${message}")
|
||||
val parsedEvent = ParseMidiMessage(message)
|
||||
println(parsedEvent ?: "Don't care")
|
||||
if (parsedEvent != null) {
|
||||
if (!parsedEvent.isNoteOff) {
|
||||
slave.enqueueBeep(100, parsedEvent.frequency())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class BeeperSlave {
|
||||
|
||||
///////////////////
|
||||
// BEEPER DRIVER //
|
||||
///////////////////
|
||||
|
||||
private val beepMaxLen = 10000
|
||||
// let's regard it as a tracker...
|
||||
private val beepQueue = ArrayList<Pair<Int, Double>>()
|
||||
private var beepCursor = -1
|
||||
private var beepQueueLineExecTimer: Millisec = 0
|
||||
private var beepQueueFired = false
|
||||
|
||||
fun update(delta: Int) {
|
||||
runBeepQueueManager(delta)
|
||||
}
|
||||
|
||||
fun runBeepQueueManager(delta: Int) {
|
||||
// start emitTone queue
|
||||
if (beepQueue.size > 0 && beepCursor == -1) {
|
||||
beepCursor = 0
|
||||
}
|
||||
|
||||
// advance emitTone queue
|
||||
if (beepCursor >= 0 && beepQueueLineExecTimer >= beepQueueGetLenOfPtn(beepCursor)) {
|
||||
beepQueueLineExecTimer -= beepQueueGetLenOfPtn(beepCursor)
|
||||
beepCursor += 1
|
||||
beepQueueFired = false
|
||||
}
|
||||
|
||||
// complete emitTone queue
|
||||
if (beepCursor >= beepQueue.size) {
|
||||
clearBeepQueue()
|
||||
}
|
||||
|
||||
// actually play queue
|
||||
if (beepCursor >= 0 && beepQueue.size > 0 && !beepQueueFired) {
|
||||
playTone(beepQueue[beepCursor].first, beepQueue[beepCursor].second)
|
||||
beepQueueFired = true
|
||||
|
||||
// delete sources that is finished. AL is limited to 256 sources. If you exceed it,
|
||||
// we won't get any more sounds played.
|
||||
AL10.alSourcei(oldBeepSource, AL10.AL_BUFFER, 0)
|
||||
AL10.alDeleteSources(oldBeepSource)
|
||||
AL10.alDeleteBuffers(oldBeepBuffer)
|
||||
}
|
||||
|
||||
if (beepQueueFired) beepQueueLineExecTimer += delta
|
||||
}
|
||||
|
||||
fun clearBeepQueue() {
|
||||
beepQueue.clear()
|
||||
beepCursor = -1
|
||||
beepQueueLineExecTimer = 0
|
||||
|
||||
//AL.destroy()
|
||||
|
||||
}
|
||||
|
||||
fun enqueueBeep(duration: Int, freq: Double) {
|
||||
beepQueue.add(Pair(Math.min(duration, beepMaxLen), freq))
|
||||
}
|
||||
|
||||
fun beepQueueGetLenOfPtn(ptnIndex: Int) = beepQueue[ptnIndex].first
|
||||
|
||||
|
||||
////////////////////
|
||||
// TONE GENERATOR //
|
||||
////////////////////
|
||||
|
||||
private val sampleRate = 44100
|
||||
private var beepSource: Int = -1
|
||||
private var beepBuffer: Int = -1
|
||||
private var oldBeepSource: Int = -1
|
||||
private var oldBeepBuffer: Int = -1
|
||||
var audioData: ByteBuffer? = null
|
||||
|
||||
/**
|
||||
* @param duration : milliseconds
|
||||
* @param rampUp
|
||||
* @param rampDown
|
||||
*
|
||||
* ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false)
|
||||
*/
|
||||
private fun makeAudioData(duration: Millisec, freq: Double,
|
||||
rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer {
|
||||
val audioData = BufferUtils.createByteBuffer(duration.times(sampleRate).div(1000))
|
||||
|
||||
val realDuration = duration * sampleRate / 1000
|
||||
val chopSize = freq / sampleRate
|
||||
|
||||
val amp = Math.max(4600.0 / freq, 1.0)
|
||||
val nHarmonics = if (freq >= 22050.0) 1
|
||||
else if (freq >= 11025.0) 2
|
||||
else if (freq >= 5512.5) 3
|
||||
else if (freq >= 2756.25) 4
|
||||
else if (freq >= 1378.125) 5
|
||||
else if (freq >= 689.0625) 6
|
||||
else 7
|
||||
|
||||
val transitionThre = 974.47218
|
||||
|
||||
// TODO volume ramping?
|
||||
if (freq == 0.0) {
|
||||
for (x in 0..realDuration - 1) {
|
||||
audioData.put(0x00.toByte())
|
||||
}
|
||||
}
|
||||
else if (freq < transitionThre) { // chopper generator (for low freq)
|
||||
for (x in 0..realDuration - 1) {
|
||||
var sine: Double = amp * Math.cos(Math.PI * 2 * x * chopSize)
|
||||
if (sine > 0.79) sine = 0.79
|
||||
else if (sine < -0.79) sine = -0.79
|
||||
audioData.put(
|
||||
(0.5 + 0.5 * sine).times(0xFF).roundInt().toByte()
|
||||
)
|
||||
}
|
||||
}
|
||||
else { // harmonics generator (for high freq)
|
||||
for (x in 0..realDuration - 1) {
|
||||
var sine: Double = 0.0
|
||||
for (k in 1..nHarmonics) { // mix only odd harmonics in order to make a squarewave
|
||||
sine += Math.sin(Math.PI * 2 * (2*k - 1) * chopSize * x) / (2*k - 1)
|
||||
}
|
||||
audioData.put(
|
||||
(0.5 + 0.5 * sine).times(0xFF).roundInt().toByte()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
audioData.rewind()
|
||||
|
||||
return audioData
|
||||
}
|
||||
|
||||
fun playTone(leninmilli: Int, freq: Double) {
|
||||
/*audioData = makeAudioData(leninmilli, freq)
|
||||
|
||||
|
||||
if (!AL.isCreated()) AL.create()
|
||||
|
||||
|
||||
// Clear error stack.
|
||||
AL10.alGetError()
|
||||
|
||||
oldBeepBuffer = beepBuffer
|
||||
beepBuffer = AL10.alGenBuffers()
|
||||
checkALError()
|
||||
|
||||
try {
|
||||
AL10.alBufferData(beepBuffer, AL10.AL_FORMAT_MONO8, audioData, sampleRate)
|
||||
checkALError()
|
||||
|
||||
oldBeepSource = beepSource
|
||||
beepSource = AL10.alGenSources()
|
||||
checkALError()
|
||||
|
||||
try {
|
||||
AL10.alSourceQueueBuffers(beepSource, beepBuffer)
|
||||
checkALError()
|
||||
|
||||
AL10.alSource3f(beepSource, AL10.AL_POSITION, 0f, 0f, 1f)
|
||||
AL10.alSourcef(beepSource, AL10.AL_REFERENCE_DISTANCE, 1f)
|
||||
AL10.alSourcef(beepSource, AL10.AL_MAX_DISTANCE, 1f)
|
||||
AL10.alSourcef(beepSource, AL10.AL_GAIN, 0.3f)
|
||||
checkALError()
|
||||
|
||||
AL10.alSourcePlay(beepSource)
|
||||
checkALError()
|
||||
}
|
||||
catch (e: ALException) {
|
||||
AL10.alDeleteSources(beepSource)
|
||||
}
|
||||
}
|
||||
catch (e: ALException) {
|
||||
AL10.alDeleteSources(beepSource)
|
||||
}*/
|
||||
}
|
||||
|
||||
// Custom implementation of Util.checkALError() that uses our custom exception.
|
||||
private fun checkALError() {
|
||||
val errorCode = AL10.alGetError()
|
||||
if (errorCode != AL10.AL_NO_ERROR) {
|
||||
throw ALException(errorCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ParseMidiMessage {
|
||||
operator fun invoke(message: MidiMessage): MidiKeyEvent? {
|
||||
val bytes = message.message
|
||||
val header = bytes[0].toUint().ushr(4) // 0b0000 - 0b1111
|
||||
if (header == 0b1000) { // note off
|
||||
return MidiKeyEvent(true, bytes[1].toInt(), bytes[2].toInt()) // no need for uint()
|
||||
}
|
||||
else if (header == 0b1001) { // note on
|
||||
return MidiKeyEvent(false, bytes[1].toInt(), bytes[2].toInt()) // no need for uint()
|
||||
}
|
||||
else { // don't care
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
data class MidiKeyEvent(val isNoteOff: Boolean, val key: Int, val velocity: Int) {
|
||||
override fun toString() = "${if (isNoteOff) "Off" else "On "} $key v$velocity"
|
||||
/**
|
||||
* @param tuning frequency of middle A (default: 440.0)
|
||||
*/
|
||||
fun frequency(tuning: Double = 440.0): Double {
|
||||
val a3 = 69 // midi note number for middle A
|
||||
|
||||
return tuning * Math.pow(2.0, (key - a3) / 12.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.ui.*
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-07-06.
|
||||
*/
|
||||
class StateMonitorCheck : BasicGameState() {
|
||||
private lateinit var uiMonitorCheck: UIHandler
|
||||
|
||||
override fun init(gc: GameContainer, g: StateBasedGame) {
|
||||
uiMonitorCheck = UIHandler(MonitorCheckUI())
|
||||
uiMonitorCheck.isVisible = true
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) {
|
||||
uiMonitorCheck.update(gc, delta)
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
||||
uiMonitorCheck.render(gc, sbg, g)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
//uiMonitorCheck.setAsClose()
|
||||
}
|
||||
|
||||
override fun getID(): Int = Terrarum.STATE_ID_CONFIG_CALIBRATE
|
||||
|
||||
class MonitorCheckUI : UICanvas {
|
||||
override var width = Terrarum.WIDTH
|
||||
override var height = Terrarum.HEIGHT
|
||||
override var openCloseTime = 150
|
||||
|
||||
override var handler: UIHandler? = null
|
||||
|
||||
private val backgroundCol = Color(0x404040)
|
||||
|
||||
private val colourLUT = IntArray(32, { 255.times(it + 1).div(32) })
|
||||
|
||||
val pictograms = ArrayList<Image>()
|
||||
val imageGallery: UIItemImageGallery
|
||||
|
||||
val instructionY = Terrarum.HEIGHT / 2//Terrarum.HEIGHT * 9 / 16
|
||||
val anykeyY = Terrarum.HEIGHT * 15 / 16
|
||||
|
||||
val maru_alt = Regex("CN|JP|K[RP]|TW")
|
||||
|
||||
init {
|
||||
if (Terrarum.gameLocale.length >= 4 && Terrarum.gameLocale.contains(maru_alt))
|
||||
pictograms.add(Image("./assets/graphics/gui/monitor_good_alt_maru.tga"))
|
||||
else
|
||||
pictograms.add(Image("./assets/graphics/gui/monitor_good.tga"))
|
||||
pictograms.add(Image("./assets/graphics/gui/monitor_bad.tga"))
|
||||
|
||||
imageGallery = UIItemImageGallery(
|
||||
this, 0, instructionY, Terrarum.WIDTH, anykeyY - instructionY, pictograms
|
||||
)
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
val titleY = Terrarum.HEIGHT * 7 / 16
|
||||
|
||||
val barWidthAll = Terrarum.WIDTH.div(100).times(100) * 9 / 10
|
||||
val barWidth: Int = barWidthAll / 32 + 1
|
||||
val barHeight = 90
|
||||
|
||||
val yCentre = Terrarum.HEIGHT.shr(1)
|
||||
|
||||
val barNumberGap = 5
|
||||
|
||||
g.background = Color.black
|
||||
// draw bars
|
||||
for (i in 0..31) {
|
||||
val labelW = g.font.getWidth(i.plus(1).toString())
|
||||
val labelH = g.font.lineHeight
|
||||
val barXstart = center(Terrarum.WIDTH, barWidthAll) + i.times(barWidth)
|
||||
val barYstart = center(yCentre, barHeight)
|
||||
|
||||
// bar start point indicator
|
||||
if (i == 0) {
|
||||
g.color = backgroundCol
|
||||
g.drawLine(
|
||||
barXstart.toFloat(), barYstart - barNumberGap - labelH.toFloat(),
|
||||
barXstart.toFloat(), barYstart - barNumberGap.toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
// bar numbers
|
||||
if (i.plus(1) and 0x1 == 0 || i.plus(1) == 1) {
|
||||
g.color = Color.white
|
||||
g.drawString(
|
||||
i.plus(1).toString(),
|
||||
barXstart + center(barWidth, labelW).toFloat(),
|
||||
barYstart - barNumberGap - labelH.toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
// actual bar
|
||||
g.color = Color(colourLUT[i], colourLUT[i], colourLUT[i])
|
||||
g.fillRect(
|
||||
barXstart.toFloat(),
|
||||
barYstart.toFloat(),
|
||||
barWidth.toFloat(),
|
||||
barHeight.toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
// messages background
|
||||
g.color = backgroundCol
|
||||
g.fillRect(
|
||||
0f, Terrarum.HEIGHT.shr(1).toFloat(),
|
||||
Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.shr(1).plus(1).toFloat()
|
||||
)
|
||||
|
||||
// labels
|
||||
g.color = Color.white
|
||||
Typography.printCentered(
|
||||
g, Lang["MENU_MONITOR_CALI_TITLE"],
|
||||
titleY,
|
||||
this
|
||||
)
|
||||
|
||||
// message text
|
||||
/*(1..12).forEach {
|
||||
Typography.printCentered(
|
||||
g, Lang["MENU_MONITOR_CALI_LABEL_$it"],
|
||||
instructionY + it.minus(2).times(g.font.lineHeight),
|
||||
this
|
||||
)
|
||||
}*/
|
||||
|
||||
// message pictogram
|
||||
imageGallery.render(gc, g)
|
||||
|
||||
|
||||
// anykey
|
||||
Typography.printCentered(
|
||||
g, Lang["MENU_LABEL_PRESS_ANYKEY"],
|
||||
anykeyY,
|
||||
this
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
}
|
||||
|
||||
override fun doOpening(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun doClosing(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun endOpening(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
private fun center(x1: Int, x2: Int) = x1.minus(x2).div(2)
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.imagefont.NewRunes
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-24.
|
||||
*/
|
||||
|
||||
class StateNewRunesTest : BasicGameState() {
|
||||
|
||||
lateinit var runes: NewRunes
|
||||
|
||||
override fun init(gc: GameContainer, game: StateBasedGame) {
|
||||
runes = NewRunes()
|
||||
runes.scale = 2
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
|
||||
g.background = Color(0x282828)
|
||||
g.font = runes
|
||||
g.color = Color(0x00c0f3)
|
||||
|
||||
val text = arrayOf(
|
||||
"ㅎㅏㅣㄹㅏㄹㅍㅏㄴㅌㅏㅈㅣ",
|
||||
"ㅈㅔㄹㄷㅏㅢㅈㅓㄴㅅㅓㄹ.", // <<insert troll_face here>>
|
||||
".22884646ㄴㄱ."
|
||||
)
|
||||
|
||||
text.forEachIndexed { index, s ->
|
||||
g.drawString(s, 30f, 30f + (runes.lineHeight * index))
|
||||
}
|
||||
}
|
||||
|
||||
override fun getID(): Int = Terrarum.STATE_ID_TEST_FONT
|
||||
}
|
||||
@@ -1,284 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.sudoplay.joise.Joise
|
||||
import com.sudoplay.joise.module.*
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.concurrent.ThreadParallel
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.ImageBuffer
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* WARNING! HAS SERIOUS MEMORY LEAK
|
||||
*
|
||||
* Created by SKYHi14 on 2017-01-30.
|
||||
*/
|
||||
class StateNoiseTester : BasicGameState() {
|
||||
|
||||
companion object {
|
||||
val imagesize = 512
|
||||
val sampleDensity = 1.0
|
||||
val noiseImageBuffer = ImageBuffer(imagesize, imagesize)
|
||||
var generating = false
|
||||
}
|
||||
override fun init(p0: GameContainer?, p1: StateBasedGame?) {
|
||||
generateNoiseImage()
|
||||
}
|
||||
|
||||
private fun noise(seed: Long): Joise {
|
||||
/* Init */
|
||||
|
||||
val joiseSeed = seed
|
||||
val lowlandMagic: Long = 0x44A21A114DBE56 // maria lindberg
|
||||
val highlandMagic: Long = 0x0114E091 // olive oyl
|
||||
val mountainMagic: Long = 0x115AA4DE2504 // lisa anderson
|
||||
val selectionMagic: Long = 0x44E10D9B100 // melody blue
|
||||
|
||||
val ground_gradient = ModuleGradient()
|
||||
ground_gradient.setGradient(0.0, 0.0, 0.0, 1.0)
|
||||
|
||||
/* Lowlands */
|
||||
|
||||
val lowland_shape_fractal = ModuleFractal()
|
||||
lowland_shape_fractal.setType(ModuleFractal.FractalType.FBM)
|
||||
lowland_shape_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT)
|
||||
lowland_shape_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
lowland_shape_fractal.setNumOctaves(2)
|
||||
lowland_shape_fractal.setFrequency(1.0)
|
||||
lowland_shape_fractal.seed = joiseSeed xor lowlandMagic
|
||||
|
||||
val lowland_autocorrect = ModuleAutoCorrect()
|
||||
lowland_autocorrect.setSource(lowland_shape_fractal)
|
||||
lowland_autocorrect.setLow(0.0)
|
||||
lowland_autocorrect.setHigh(1.0)
|
||||
|
||||
val lowland_scale = ModuleScaleOffset()
|
||||
lowland_scale.setSource(lowland_autocorrect)
|
||||
lowland_scale.setScale(0.2)
|
||||
lowland_scale.setOffset(-0.25)
|
||||
|
||||
val lowland_y_scale = ModuleScaleDomain()
|
||||
lowland_y_scale.setSource(lowland_scale)
|
||||
lowland_y_scale.setScaleY(0.0)
|
||||
|
||||
val lowland_terrain = ModuleTranslateDomain()
|
||||
lowland_terrain.setSource(ground_gradient)
|
||||
lowland_terrain.setAxisYSource(lowland_y_scale)
|
||||
|
||||
|
||||
/* highlands */
|
||||
|
||||
val highland_shape_fractal = ModuleFractal()
|
||||
highland_shape_fractal.setType(ModuleFractal.FractalType.RIDGEMULTI)
|
||||
highland_shape_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT)
|
||||
highland_shape_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
highland_shape_fractal.setNumOctaves(2)
|
||||
highland_shape_fractal.setFrequency(2.0)
|
||||
highland_shape_fractal.seed = joiseSeed xor highlandMagic
|
||||
|
||||
val highland_autocorrect = ModuleAutoCorrect()
|
||||
highland_autocorrect.setSource(highland_shape_fractal)
|
||||
highland_autocorrect.setLow(0.0)
|
||||
highland_autocorrect.setHigh(1.0)
|
||||
|
||||
val highland_scale = ModuleScaleOffset()
|
||||
highland_scale.setSource(highland_autocorrect)
|
||||
highland_scale.setScale(0.45)
|
||||
highland_scale.setOffset(0.0)
|
||||
|
||||
val highland_y_scale = ModuleScaleDomain()
|
||||
highland_y_scale.setSource(highland_scale)
|
||||
highland_y_scale.setScaleY(0.0)
|
||||
|
||||
val highland_terrain = ModuleTranslateDomain()
|
||||
highland_terrain.setSource(ground_gradient)
|
||||
highland_terrain.setAxisYSource(highland_y_scale)
|
||||
|
||||
|
||||
/* mountains */
|
||||
|
||||
val mountain_shape_fractal = ModuleFractal()
|
||||
mountain_shape_fractal.setType(ModuleFractal.FractalType.BILLOW)
|
||||
mountain_shape_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT)
|
||||
mountain_shape_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
mountain_shape_fractal.setNumOctaves(4)
|
||||
mountain_shape_fractal.setFrequency(1.0)
|
||||
mountain_shape_fractal.seed = joiseSeed xor mountainMagic
|
||||
|
||||
val mountain_autocorrect = ModuleAutoCorrect()
|
||||
mountain_autocorrect.setSource(mountain_shape_fractal)
|
||||
mountain_autocorrect.setLow(0.0)
|
||||
mountain_autocorrect.setHigh(1.0)
|
||||
|
||||
val mountain_scale = ModuleScaleOffset()
|
||||
mountain_scale.setSource(mountain_autocorrect)
|
||||
mountain_scale.setScale(0.75)
|
||||
mountain_scale.setOffset(0.25)
|
||||
|
||||
val mountain_y_scale = ModuleScaleDomain()
|
||||
mountain_y_scale.setSource(mountain_scale)
|
||||
mountain_y_scale.setScaleY(0.1) // controls "quirkiness" of the mountain
|
||||
|
||||
val mountain_terrain = ModuleTranslateDomain()
|
||||
mountain_terrain.setSource(ground_gradient)
|
||||
mountain_terrain.setAxisYSource(mountain_y_scale)
|
||||
|
||||
|
||||
/* selection */
|
||||
|
||||
val terrain_type_fractal = ModuleFractal()
|
||||
terrain_type_fractal.setType(ModuleFractal.FractalType.FBM)
|
||||
terrain_type_fractal.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.GRADIENT)
|
||||
terrain_type_fractal.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
terrain_type_fractal.setNumOctaves(3)
|
||||
terrain_type_fractal.setFrequency(0.5)
|
||||
terrain_type_fractal.seed = joiseSeed xor selectionMagic
|
||||
|
||||
val terrain_autocorrect = ModuleAutoCorrect()
|
||||
terrain_autocorrect.setSource(terrain_type_fractal)
|
||||
terrain_autocorrect.setLow(0.0)
|
||||
terrain_autocorrect.setHigh(1.0)
|
||||
|
||||
val terrain_type_cache = ModuleCache()
|
||||
terrain_type_cache.setSource(terrain_autocorrect)
|
||||
|
||||
val highland_mountain_select = ModuleSelect()
|
||||
highland_mountain_select.setLowSource(highland_terrain)
|
||||
highland_mountain_select.setHighSource(mountain_terrain)
|
||||
highland_mountain_select.setControlSource(terrain_type_cache)
|
||||
highland_mountain_select.setThreshold(0.55)
|
||||
highland_mountain_select.setFalloff(0.15)
|
||||
|
||||
val highland_lowland_select = ModuleSelect()
|
||||
highland_lowland_select.setLowSource(lowland_terrain)
|
||||
highland_lowland_select.setHighSource(highland_mountain_select)
|
||||
highland_lowland_select.setControlSource(terrain_type_cache)
|
||||
highland_lowland_select.setThreshold(0.25)
|
||||
highland_lowland_select.setFalloff(0.15)
|
||||
|
||||
val ground_select = ModuleSelect()
|
||||
ground_select.setLowSource(0.0)
|
||||
ground_select.setHighSource(1.0)
|
||||
ground_select.setThreshold(0.5)
|
||||
ground_select.setControlSource(highland_lowland_select)
|
||||
|
||||
|
||||
val joise = Joise(ground_select)
|
||||
return joise
|
||||
}
|
||||
|
||||
fun generateNoiseImage() {
|
||||
val noiseModule = noise(HQRNG().nextLong()) // change noise function here
|
||||
|
||||
for (y in 0..imagesize - 1) {
|
||||
for (x in 0..imagesize - 1) {
|
||||
noiseImageBuffer.setRGBA(x, y, 0, 0, 0, 255)
|
||||
}
|
||||
}
|
||||
|
||||
for (i in 0..Terrarum.THREADS - 1) {
|
||||
ThreadParallel.map(
|
||||
i,
|
||||
ThreadRunNoiseSampling(
|
||||
imagesize.toFloat().div(Terrarum.THREADS).times(i).roundInt(),
|
||||
imagesize.toFloat().div(Terrarum.THREADS).times(i.plus(1)).roundInt() - 1,
|
||||
noiseModule
|
||||
),
|
||||
"SampleJoiseMap"
|
||||
)
|
||||
}
|
||||
|
||||
ThreadParallel.startAll()
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle(
|
||||
Terrarum.NAME +
|
||||
" — F: ${Terrarum.appgc.fps} (${Terrarum.TARGET_INTERNAL_FPS})" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
|
||||
)
|
||||
|
||||
|
||||
if (ThreadParallel.allFinished()) generating = false
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TOOL_NOISEGEN
|
||||
|
||||
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
||||
g.color = Color.red
|
||||
g.drawString("Press SPACE to generate new noise", 8f, 8f)
|
||||
g.drawString("CPUs: ${Terrarum.THREADS}", Terrarum.WIDTH - 90f, 8f)
|
||||
|
||||
g.background = Color.cyan
|
||||
g.drawImage(noiseImageBuffer.image,//noiseImage,
|
||||
Terrarum.WIDTH.minus(imagesize).div(2).toFloat(),
|
||||
Terrarum.HEIGHT.minus(imagesize).div(2).toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
if (c == ' ' && !generating) {
|
||||
println("Generating noise, may take a while")
|
||||
generating = true
|
||||
generateNoiseImage()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ThreadRunNoiseSampling(val startIndex: Int, val endIndex: Int, val joise: Joise) : Runnable {
|
||||
/*override fun run() {
|
||||
for (sy in startIndex..endIndex) {
|
||||
for (sx in 0..imagesize - 1) {
|
||||
val y = sy.toDouble() / imagesize
|
||||
val x = sx.toDouble() / imagesize
|
||||
|
||||
val sampleOffset = sampleDensity
|
||||
// 4-D toroidal sampling (looped H and V)
|
||||
val sampleTheta1 = x * Math.PI * 2.0
|
||||
val sampleTheta2 = y * Math.PI * 2.0
|
||||
val sampleX = Math.sin(sampleTheta1) * sampleDensity + sampleDensity
|
||||
val sampleY = Math.cos(sampleTheta1) * sampleDensity + sampleDensity
|
||||
val sampleZ = Math.sin(sampleTheta2) * sampleDensity + sampleDensity
|
||||
val sampleW = Math.cos(sampleTheta2) * sampleDensity + sampleDensity
|
||||
|
||||
val noise = joise.get(
|
||||
sampleX, sampleY, sampleZ, sampleW
|
||||
) // autocorrection REQUIRED!
|
||||
|
||||
val noiseCol = noise.times(255f).toInt()
|
||||
noiseImageBuffer.setRGBA(sx, sy, noiseCol, noiseCol, noiseCol, 255)
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
override fun run() {
|
||||
for (sy in startIndex..endIndex) {
|
||||
for (sx in 0..imagesize - 1) {
|
||||
val y = sy.toDouble() / imagesize * 1.5 -.6
|
||||
val x = sx.toDouble() / imagesize
|
||||
|
||||
val sampleOffset = sampleDensity
|
||||
// 4-D toroidal sampling (looped H and V)
|
||||
val sampleTheta1 = x * Math.PI * 2.0
|
||||
val sampleX = Math.sin(sampleTheta1) * sampleDensity + sampleDensity
|
||||
val sampleZ = Math.cos(sampleTheta1) * sampleDensity + sampleDensity
|
||||
val sampleY = y
|
||||
|
||||
val noise = joise.get(
|
||||
sampleX, sampleY, sampleZ
|
||||
) // autocorrection REQUIRED!
|
||||
|
||||
val noiseCol = noise.times(255f).toInt()
|
||||
noiseImageBuffer.setRGBA(sx, sy, noiseCol, noiseCol, noiseCol, 255)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.sudoplay.joise.Joise
|
||||
import com.sudoplay.joise.module.*
|
||||
import net.torvald.terrarum.Terrarum.STATE_ID_TOOL_NOISEGEN
|
||||
import net.torvald.terrarum.concurrent.ThreadParallel
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-12-21.
|
||||
*/
|
||||
class StateNoiseTexGen : BasicGameState() {
|
||||
|
||||
companion object {
|
||||
val imagesize = 512
|
||||
val sampleDensity = 1.0
|
||||
val noiseImageBuffer = ImageBuffer(imagesize, imagesize)
|
||||
var generating = false
|
||||
}
|
||||
override fun init(p0: GameContainer?, p1: StateBasedGame?) {
|
||||
generateNoiseImage()
|
||||
}
|
||||
|
||||
private fun noiseRidged(): Joise {
|
||||
val ridged = ModuleFractal()
|
||||
ridged.setType(ModuleFractal.FractalType.RIDGEMULTI)
|
||||
ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
ridged.setNumOctaves(4)
|
||||
ridged.setFrequency(1.0)
|
||||
ridged.seed = Random().nextLong()
|
||||
|
||||
val ridged_autocorrect = ModuleAutoCorrect()
|
||||
ridged_autocorrect.setRange(0.0, 1.0)
|
||||
ridged_autocorrect.setSource(ridged)
|
||||
|
||||
return Joise(ridged_autocorrect)
|
||||
}
|
||||
|
||||
private fun noiseBrownian(): Joise {
|
||||
val ridged = ModuleFractal()
|
||||
ridged.setType(ModuleFractal.FractalType.FBM)
|
||||
ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
ridged.setNumOctaves(8)
|
||||
ridged.setFrequency(1.0)
|
||||
ridged.seed = Random().nextLong()
|
||||
|
||||
val ridged_autocorrect = ModuleAutoCorrect()
|
||||
ridged_autocorrect.setRange(0.0, 1.0)
|
||||
ridged_autocorrect.setSource(ridged)
|
||||
|
||||
return Joise(ridged_autocorrect)
|
||||
}
|
||||
|
||||
private fun noiseBrownianGranite(): Joise {
|
||||
val ridged = ModuleFractal()
|
||||
ridged.setType(ModuleFractal.FractalType.FBM)
|
||||
ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
ridged.setNumOctaves(2)
|
||||
ridged.setFrequency(16.0)
|
||||
ridged.seed = Random().nextLong()
|
||||
|
||||
val brownian_select = ModuleSelect()
|
||||
brownian_select.setControlSource(ridged)
|
||||
brownian_select.setThreshold(0.8)
|
||||
brownian_select.setLowSource(0.0)
|
||||
brownian_select.setHighSource(1.0)
|
||||
|
||||
return Joise(brownian_select)
|
||||
}
|
||||
|
||||
private fun noiseBillowFractal(): Joise {
|
||||
val ridged = ModuleFractal()
|
||||
ridged.setType(ModuleFractal.FractalType.BILLOW)
|
||||
ridged.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.QUINTIC)
|
||||
ridged.setNumOctaves(8)
|
||||
ridged.setFrequency(1.0)
|
||||
ridged.seed = Random().nextLong()
|
||||
|
||||
val ridged_autocorrect = ModuleAutoCorrect()
|
||||
ridged_autocorrect.setRange(0.0, 1.0)
|
||||
ridged_autocorrect.setSource(ridged)
|
||||
|
||||
return Joise(ridged_autocorrect)
|
||||
}
|
||||
|
||||
private fun noiseSimplex(): Joise {
|
||||
val simplex = ModuleFractal()
|
||||
simplex.seed = Random().nextLong()
|
||||
simplex.setAllSourceBasisTypes(ModuleBasisFunction.BasisType.SIMPLEX)
|
||||
simplex.setAllSourceInterpolationTypes(ModuleBasisFunction.InterpolationType.LINEAR)
|
||||
simplex.setNumOctaves(2)
|
||||
simplex.setFrequency(1.0)
|
||||
|
||||
val simplex_autocorrect = ModuleAutoCorrect()
|
||||
simplex_autocorrect.setRange(0.0, 1.0)
|
||||
simplex_autocorrect.setSource(simplex)
|
||||
|
||||
return Joise(simplex_autocorrect)
|
||||
}
|
||||
|
||||
private fun noiseCellular(): Joise {
|
||||
val cellgen = ModuleCellGen()
|
||||
cellgen.seed = Random().nextLong()
|
||||
|
||||
val cellular = ModuleCellular()
|
||||
cellular.setCellularSource(cellgen)
|
||||
cellular.setCoefficients(-1.0, 1.0, 0.0, 0.0)
|
||||
|
||||
val cellular_autocorrect = ModuleAutoCorrect()
|
||||
cellular_autocorrect.setRange(0.0, 1.0)
|
||||
cellular_autocorrect.setSource(cellular)
|
||||
|
||||
return Joise(cellular_autocorrect)
|
||||
}
|
||||
|
||||
fun generateNoiseImage() {
|
||||
val noiseModule = noiseBrownianGranite() // change noise function here
|
||||
|
||||
for (y in 0..imagesize - 1) {
|
||||
for (x in 0..imagesize - 1) {
|
||||
noiseImageBuffer.setRGBA(x, y, 0, 0, 0, 255)
|
||||
}
|
||||
}
|
||||
|
||||
for (i in 0..Terrarum.THREADS - 1) {
|
||||
ThreadParallel.map(
|
||||
i,
|
||||
ThreadRunNoiseSampling(
|
||||
imagesize.toFloat().div(Terrarum.THREADS).times(i).roundInt(),
|
||||
imagesize.toFloat().div(Terrarum.THREADS).times(i.plus(1)).roundInt() - 1,
|
||||
noiseModule
|
||||
),
|
||||
"SampleJoiseMap"
|
||||
)
|
||||
}
|
||||
|
||||
ThreadParallel.startAll()
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, sbg: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}")
|
||||
|
||||
if (ThreadParallel.allFinished()) generating = false
|
||||
}
|
||||
|
||||
override fun getID() = STATE_ID_TOOL_NOISEGEN
|
||||
|
||||
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
|
||||
g.color = Color.red
|
||||
g.drawString("Press SPACE to generate new noise", 8f, 8f)
|
||||
g.drawString("CPUs: ${Terrarum.THREADS}", Terrarum.WIDTH - 90f, 8f)
|
||||
|
||||
g.background = Color.cyan
|
||||
val img = noiseImageBuffer.image
|
||||
g.drawImage(img,//noiseImage,
|
||||
Terrarum.WIDTH.minus(imagesize).div(2).toFloat(),
|
||||
Terrarum.HEIGHT.minus(imagesize).div(2).toFloat()
|
||||
)
|
||||
|
||||
img.destroy()
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
if (c == ' ' && !generating) {
|
||||
println("Generating noise, may take a while")
|
||||
generating = true
|
||||
generateNoiseImage()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ThreadRunNoiseSampling(val startIndex: Int, val endIndex: Int, val joise: Joise) : Runnable {
|
||||
override fun run() {
|
||||
for (sy in startIndex..endIndex) {
|
||||
for (sx in 0..imagesize - 1) {
|
||||
val y = sy.toDouble() / imagesize
|
||||
val x = sx.toDouble() / imagesize
|
||||
|
||||
val sampleOffset = sampleDensity
|
||||
// 4-D toroidal sampling (looped H and V)
|
||||
val sampleTheta1 = x * Math.PI * 2.0
|
||||
val sampleTheta2 = y * Math.PI * 2.0
|
||||
val sampleX = Math.sin(sampleTheta1) * sampleDensity + sampleDensity
|
||||
val sampleY = Math.cos(sampleTheta1) * sampleDensity + sampleDensity
|
||||
val sampleZ = Math.sin(sampleTheta2) * sampleDensity + sampleDensity
|
||||
val sampleW = Math.cos(sampleTheta2) * sampleDensity + sampleDensity
|
||||
|
||||
val noise = joise.get(
|
||||
sampleX, sampleY, sampleZ, sampleW
|
||||
) // autocorrection REQUIRED!
|
||||
|
||||
val noiseCol = noise.times(255f).toInt()
|
||||
noiseImageBuffer.setRGBA(sx, sy, noiseCol, noiseCol, noiseCol, 255)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import org.lwjgl.opengl.*
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.opengl.renderer.SGL
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import shader.Shader
|
||||
import org.lwjgl.opengl.GL11
|
||||
import org.lwjgl.opengl.ARBShaderObjects
|
||||
import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.close
|
||||
import jdk.nashorn.internal.runtime.ScriptingFunctions.readLine
|
||||
import net.torvald.terrarum.Terrarum.STATE_ID_TEST_SHADER
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.opengl.TextureImpl
|
||||
import java.io.InputStreamReader
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-01-23.
|
||||
*/
|
||||
class StateShaderTest : BasicGameState() {
|
||||
override fun getID() = STATE_ID_TEST_SHADER
|
||||
|
||||
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
}
|
||||
|
||||
private lateinit var shaderTest: Shader
|
||||
private lateinit var testImage: Image
|
||||
|
||||
override fun enter(container: GameContainer?, game: StateBasedGame?) {
|
||||
shaderTest = Shader.makeShader("./assets/test.vert", "./assets/test.frag")
|
||||
|
||||
testImage = Image("./assets/test_texture.tga")
|
||||
//testImage = Image("./logo_repository.png")
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
|
||||
Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}")
|
||||
}
|
||||
|
||||
override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) {
|
||||
val x = 10f
|
||||
val y = 10f
|
||||
val width = testImage.width
|
||||
val height = testImage.height
|
||||
val textureWidth = testImage.textureWidth
|
||||
val textureHeight = testImage.textureHeight
|
||||
val textureOffsetX = testImage.textureOffsetX
|
||||
val textureOffsetY = testImage.textureOffsetY
|
||||
|
||||
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT)
|
||||
// bind texture
|
||||
// glBegin(SGL.GL_QUADS)
|
||||
// do shader
|
||||
// glEnd()
|
||||
|
||||
|
||||
|
||||
//testImage.bind()
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS)
|
||||
|
||||
//GL20.glUseProgram(0)
|
||||
shaderTest.startShader()
|
||||
//GL13.glActiveTexture(testImage.texture.textureID)
|
||||
//GL11.glBindTexture(GL13.GL_TEXTURE0, testImage.texture.textureID)
|
||||
//testImage.bind()
|
||||
shaderTest.setUniformIntVariable("u_texture", 0)
|
||||
|
||||
/*GL11.glTexCoord2f(textureOffsetX, textureOffsetY)
|
||||
GL11.glVertex3f(x, y, 0f)
|
||||
GL11.glTexCoord2f(textureOffsetX, textureOffsetY + textureHeight)
|
||||
GL11.glVertex3f(x, y + height, 0f)
|
||||
GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY + textureHeight)
|
||||
GL11.glVertex3f(x + width, y + height, 0f)
|
||||
GL11.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY)
|
||||
GL11.glVertex3f(x + width, y, 0f)*/
|
||||
|
||||
g!!.color = Color.orange
|
||||
g!!.fillRect(10f, 10f, 512f, 512f)
|
||||
|
||||
GL20.glUseProgram(0)
|
||||
GL11.glEnd()
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.ui.DrawUtil
|
||||
import net.torvald.terrarum.ui.NullUI
|
||||
import net.torvald.terrarum.ui.UIItemImageGallery
|
||||
import net.torvald.terrarum.ui.Typography
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-08-04.
|
||||
*/
|
||||
class StateSplash : BasicGameState() {
|
||||
|
||||
val pictogramCollection = ArrayList<Image>()
|
||||
|
||||
val virtualImageHeight = 100
|
||||
var imageBoardHeight = 0
|
||||
var imageBoardOffset = 0
|
||||
|
||||
lateinit var fadeSheet: Image
|
||||
lateinit var thisG: Graphics
|
||||
|
||||
var opacity = 0f
|
||||
|
||||
val fadeTime = 500
|
||||
var fadeTimer = -1
|
||||
|
||||
var anykey_hit = false
|
||||
|
||||
val backgroundColour = Color(0x303030)
|
||||
|
||||
val deltathre = 500
|
||||
|
||||
val auto_dismiss = 6500
|
||||
|
||||
var opened = false
|
||||
|
||||
var init = false
|
||||
|
||||
lateinit var imageGallery: UIItemImageGallery
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
// pre-load lang
|
||||
Lang["MENU_LANGUAGE_THIS"]
|
||||
|
||||
pictogramCollection.add(Image("./assets/graphics/gui/health_take_a_break.tga"))
|
||||
pictogramCollection.add(Image("./assets/graphics/gui/health_distance.tga"))
|
||||
|
||||
fadeSheet = Image(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||
thisG = fadeSheet.graphics
|
||||
thisG.font = Terrarum.fontGame
|
||||
|
||||
imageBoardHeight = Terrarum.HEIGHT - thisG.font.lineHeight.times(6)
|
||||
imageBoardOffset = thisG.font.lineHeight.times(3)
|
||||
|
||||
imageGallery = UIItemImageGallery(
|
||||
NullUI(), 0, imageBoardOffset, Terrarum.WIDTH, imageBoardHeight, pictogramCollection
|
||||
)
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
// next splash or load next scene
|
||||
if (anykey_hit && opacity < 0.0001f) {
|
||||
game.enterState(Terrarum.STATE_ID_GAME)
|
||||
}
|
||||
|
||||
// fade-in
|
||||
if (delta < deltathre) {
|
||||
init = true
|
||||
fadeTimer += delta
|
||||
|
||||
if (opacity < 1f && !anykey_hit) {
|
||||
opacity = FastMath.interpolateLinear(
|
||||
fadeTimer.toFloat() / fadeTime, 0f, 1f
|
||||
)
|
||||
}
|
||||
else if (opacity > 0f && anykey_hit) {
|
||||
opacity = FastMath.interpolateLinear(
|
||||
fadeTimer.toFloat() / fadeTime, 1f, 0f
|
||||
)
|
||||
}
|
||||
|
||||
if (!opened && fadeTimer >= fadeTime && !anykey_hit) {
|
||||
fadeTimer = 0
|
||||
opened = true
|
||||
}
|
||||
}
|
||||
|
||||
// auto dismiss
|
||||
if (opened && fadeTimer >= auto_dismiss) {
|
||||
doAnykeyThingy()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getID(): Int = Terrarum.STATE_ID_SPLASH
|
||||
|
||||
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
thisG.color = backgroundColour
|
||||
thisG.fillRect(0f, 0f, fadeSheet.width.toFloat(), fadeSheet.height.toFloat())
|
||||
|
||||
thisG.color = Color.white
|
||||
|
||||
Typography.printCentered(thisG, Lang["APP_WARNING_HEALTH_AND_SAFETY"],
|
||||
thisG.font.lineHeight * 2)
|
||||
|
||||
Typography.printCentered(thisG, Lang["MENU_LABEL_PRESS_ANYKEY"],
|
||||
Terrarum.HEIGHT - thisG.font.lineHeight.times(3))
|
||||
|
||||
imageGallery.render(container, thisG)
|
||||
|
||||
g.drawImage(fadeSheet, 0f, 0f, Color(1f, 1f, 1f, opacity))
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
doAnykeyThingy()
|
||||
}
|
||||
|
||||
override fun controllerButtonPressed(controller: Int, button: Int) {
|
||||
doAnykeyThingy()
|
||||
}
|
||||
|
||||
private fun doAnykeyThingy() {
|
||||
if (!anykey_hit) {
|
||||
anykey_hit = true
|
||||
fadeTimer = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-04-22.
|
||||
*/
|
||||
class StateStutterTest : BasicGameState() {
|
||||
|
||||
private val testImage = Image(4096, 1728)
|
||||
private val testImageG = testImage.graphics
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}")
|
||||
|
||||
|
||||
if (container.input.isKeyDown(Key.UP))
|
||||
dy -= moveDelta
|
||||
if (container.input.isKeyDown(Key.DOWN))
|
||||
dy += moveDelta
|
||||
if (container.input.isKeyDown(Key.LEFT))
|
||||
dx -= moveDelta
|
||||
if (container.input.isKeyDown(Key.RIGHT))
|
||||
dx += moveDelta
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_REFRESHRATE
|
||||
|
||||
private var imageMade = false
|
||||
|
||||
private var moveDelta = 3
|
||||
private var dx = 0
|
||||
private var dy = 0
|
||||
|
||||
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
if (!imageMade) {
|
||||
testImageG.font = Terrarum.fontGame
|
||||
testImageG.color = Color.white
|
||||
|
||||
(0x3400..0x9FFF).forEach {
|
||||
testImageG.drawString(
|
||||
"${it.toChar()}",
|
||||
(it - 0x3400) % 256 * 16f,
|
||||
(it - 0x3400) / 256 * 16f
|
||||
)
|
||||
}
|
||||
|
||||
testImageG.flush()
|
||||
|
||||
imageMade = true
|
||||
}
|
||||
|
||||
g.translate(-dx.toFloat(), -dy.toFloat())
|
||||
g.drawImage(testImage, 0f, 0f)
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.colourutil.ColourTemp
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.random.TileableValueNoise
|
||||
import net.torvald.terrarum.gameactors.floorInt
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.ALException
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
import org.lwjgl.BufferUtils
|
||||
import org.lwjgl.openal.AL
|
||||
import org.lwjgl.openal.AL10
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.*
|
||||
import javax.sound.sampled.AudioFormat
|
||||
import javax.sound.sampled.AudioInputStream
|
||||
import javax.sound.sampled.AudioSystem
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-05.
|
||||
*/
|
||||
class StateTestingLightning : BasicGameState() {
|
||||
|
||||
val lightning_start = Point2d(50.0, 100.0)
|
||||
val lightning_end = Point2d(750.0, 300.0)
|
||||
|
||||
val bolt = LightingBolt(lightning_start, lightning_end, 50)
|
||||
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
reseed(genOnly = true)
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
|
||||
/*timer += delta
|
||||
if (timer > regenTime) {
|
||||
timer -= regenTime
|
||||
reseed()
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_GFX
|
||||
|
||||
|
||||
private var timer = 0
|
||||
private var regenTime = 17
|
||||
|
||||
private var seed = System.nanoTime()
|
||||
|
||||
val samples = 128
|
||||
|
||||
val lightningXgen = TileableValueNoise(8, 0.67f, samples, 8)
|
||||
val lightningYgen = TileableValueNoise(8, 0.58f, samples, 4)
|
||||
|
||||
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
g.color = ColourTemp(7500)
|
||||
g.lineWidth = 3f
|
||||
|
||||
//g.drawLine(lightning_start, lightning_end)
|
||||
//bolt.draw(g)
|
||||
|
||||
// TODO rotational transformmation for the points
|
||||
// (newX, newY) = (x cos(theta) - y sin(theta), x sin(theta) + y cos(theta))
|
||||
|
||||
|
||||
val ampY = 40f
|
||||
val ampX = 6
|
||||
val xoff = 10f
|
||||
val yoff = 300f
|
||||
|
||||
for (x in 0..lightningYgen.width - 1) {
|
||||
val pXstart = (x + lightningXgen[x ]) * ampX + xoff
|
||||
val pXend = (x + 1 + lightningXgen[x + 1]) * ampX + xoff
|
||||
val pYstart = lightningYgen[x ] * ampY + yoff
|
||||
val pYend = lightningYgen[x + 1] * ampY + yoff
|
||||
|
||||
g.drawLine(pXstart, pYstart, pXend, pYend)
|
||||
}
|
||||
|
||||
g.color = Color.red
|
||||
g.lineWidth = 1f
|
||||
|
||||
g.drawLine(xoff, yoff, xoff + lightningYgen.width * ampX, yoff)
|
||||
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
if (c == ' ') reseed()
|
||||
}
|
||||
|
||||
private fun reseed(genOnly: Boolean = false) {
|
||||
if (!genOnly) seed = System.nanoTime()
|
||||
lightningXgen.generate(0x51621DL xor seed)
|
||||
lightningYgen.generate(seed)
|
||||
}
|
||||
}
|
||||
|
||||
class LightingBolt(val start: Point2d, val end: Point2d, val segments: Int) {
|
||||
val mainBolt = LinkedList<Point2d>() //Pair<Length, Y-Pos>
|
||||
|
||||
val boltYDev = 20.0
|
||||
|
||||
init {
|
||||
val length = start.length(end)
|
||||
|
||||
for (i in 0..segments - 1) {
|
||||
mainBolt.add(
|
||||
Point2d(
|
||||
start.x + length / segments * i,
|
||||
start.y + HQRNG().nextFloat().times(2.0).minus(1.0).times(boltYDev)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun draw(g: Graphics) {
|
||||
for (i in 0..segments - 1) {
|
||||
val startpoint = mainBolt[i]
|
||||
val endpoint = if (i == segments - 1) end else mainBolt[i + 1]
|
||||
|
||||
g.drawLine(startpoint, endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
fun Graphics.drawLine(p1: Point2d, p2: Point2d) {
|
||||
drawLine(p1.x.toFloat(), p1.y.toFloat(), p2.x.toFloat(), p2.y.toFloat())
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.itemproperties.IVKey
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.ui.*
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
*/
|
||||
class StateUITest : BasicGameState() {
|
||||
|
||||
val ui: UIHandler
|
||||
|
||||
private val actor = object : Actor(RenderOrder.FRONT), Pocketed {
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
override fun onActorValueChange(key: String, value: Any?) {
|
||||
}
|
||||
|
||||
override var inventory: ActorInventory = ActorInventory(this, 100, ActorInventory.CAPACITY_MODE_WEIGHT)
|
||||
}
|
||||
|
||||
init {
|
||||
ui = UIHandler(UIInventory(actor, 900, Terrarum.HEIGHT - 160, 220))
|
||||
|
||||
ui.posX = 0
|
||||
ui.posY = 60
|
||||
ui.isVisible = true
|
||||
|
||||
|
||||
|
||||
// these are the test codes.
|
||||
// Item properties must be pre-composed using CSV/JSON, and read and made into the item instance
|
||||
// using factory/builder pattern. @see ItemCodex
|
||||
|
||||
actor.inventory.add(object : GameItem() {
|
||||
init {
|
||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER
|
||||
}
|
||||
override var dynamicID: Int = 5656
|
||||
override val originalID = dynamicID
|
||||
override val isUnique: Boolean = true
|
||||
override var originalName: String = "Test tool"
|
||||
override var baseMass: Double = 12.0
|
||||
override var baseToolSize: Double? = 8.0
|
||||
override var inventoryCategory: String = GameItem.Category.TOOL
|
||||
override var maxDurability: Int = 143
|
||||
override var durability: Float = 64f
|
||||
override var stackable = false
|
||||
override val isDynamic = true
|
||||
override val material = Material(0,0,0,0,0,0,0,0,0,0.0)
|
||||
})
|
||||
actor.inventory.getByDynamicID(5656)!!.item.name = "Test tool"
|
||||
|
||||
actor.inventory.add(object : GameItem() {
|
||||
init {
|
||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT
|
||||
}
|
||||
override var dynamicID: Int = 4633
|
||||
override val originalID = dynamicID
|
||||
override val isUnique: Boolean = true
|
||||
override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN"
|
||||
override var baseMass: Double = 1.4
|
||||
override var baseToolSize: Double? = null
|
||||
override var inventoryCategory: String = GameItem.Category.MISC
|
||||
override var stackable = false
|
||||
override val isDynamic = false
|
||||
override val material = Material(0,0,0,0,0,0,0,0,0,0.0)
|
||||
})
|
||||
|
||||
actor.inventory.add(ItemCodex[16], 543)
|
||||
|
||||
actor.inventory.getByDynamicID(Block.STONE)!!.item equipTo actor
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}")
|
||||
|
||||
ui.update(container, delta)
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_UI1
|
||||
|
||||
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
blendNormal()
|
||||
g.color = Color.green
|
||||
g.fillRect(0f, 0f, 2048f, 2048f)
|
||||
|
||||
|
||||
|
||||
ui.render(container, game, g)
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.SimpleTextTerminal
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.Teletype
|
||||
import net.torvald.terrarum.virtualcomputer.terminal.TeletypeTerminal
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
import org.newdawn.slick.state.BasicGameState
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
|
||||
/**
|
||||
* ComputerCraft/OpenComputers like-alike, just for fun!
|
||||
*
|
||||
* Created by minjaesong on 16-09-07.
|
||||
*/
|
||||
class StateVTTest : BasicGameState() {
|
||||
|
||||
// HiRes: 100x64, LoRes: 80x25
|
||||
val computerInside = TerrarumComputer(peripheralSlots = 8)
|
||||
val vt = SimpleTextTerminal(SimpleTextTerminal.BLUE_NOVELTY, 80, 25,
|
||||
computerInside, colour = false, hires = false)
|
||||
|
||||
|
||||
val vtUI = Image(vt.displayW, vt.displayH)
|
||||
|
||||
|
||||
init {
|
||||
computerInside.attachTerminal(vt)
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer, game: StateBasedGame) {
|
||||
//vt.openInput()
|
||||
}
|
||||
|
||||
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
|
||||
Terrarum.appgc.setTitle("VT — F: ${container.fps}" +
|
||||
" — M: ${Terrarum.memInUse}M / ${Terrarum.memXmx}M")
|
||||
vt.update(container, delta)
|
||||
computerInside.update(container, delta)
|
||||
}
|
||||
|
||||
override fun getID() = Terrarum.STATE_ID_TEST_TTY
|
||||
|
||||
private val paperColour = Color(0xfffce6)
|
||||
|
||||
val vtUIrenderX = Terrarum.WIDTH.minus(vtUI.width).div(2f)
|
||||
val vtUIrenderY = Terrarum.HEIGHT.minus(vtUI.height).div(2f)
|
||||
|
||||
override fun render(container: GameContainer, game: StateBasedGame, g: Graphics) {
|
||||
vt.render(container, vtUI.graphics)
|
||||
|
||||
|
||||
blendNormal()
|
||||
g.drawImage(vtUI, vtUIrenderX, vtUIrenderY)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
vt.keyPressed(key, c)
|
||||
}
|
||||
}
|
||||
@@ -1,689 +0,0 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonPrimitive
|
||||
import net.torvald.imagefont.GameFontImpl
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.utils.JsonWriter
|
||||
import net.torvald.imagefont.TinyAlphNum
|
||||
import net.torvald.terrarum.gamecontroller.mouseTileX
|
||||
import net.torvald.terrarum.gamecontroller.mouseTileY
|
||||
import net.torvald.terrarum.gameworld.toUint
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.lwjgl.input.Controllers
|
||||
import org.lwjgl.opengl.*
|
||||
import org.newdawn.slick.*
|
||||
import org.newdawn.slick.opengl.Texture
|
||||
import org.newdawn.slick.state.StateBasedGame
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.ByteOrder
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.logging.FileHandler
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.Logger
|
||||
import java.util.logging.SimpleFormatter
|
||||
|
||||
const val GAME_NAME = "Terrarum"
|
||||
|
||||
typealias Millisec = Int
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 15-12-30.
|
||||
*/
|
||||
object Terrarum : StateBasedGame(GAME_NAME) {
|
||||
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// GLOBAL IMMUTABLE CONFIGS //
|
||||
//////////////////////////////
|
||||
var WIDTH = 1072
|
||||
var HEIGHT = 742 // IMAX ratio
|
||||
|
||||
val RENDER_FPS = getConfigInt("displayfps")
|
||||
val USE_VSYNC = getConfigBoolean("usevsync")
|
||||
var VSYNC = USE_VSYNC
|
||||
val VSYNC_TRIGGER_THRESHOLD = 56
|
||||
|
||||
val HALFW: Int
|
||||
get() = WIDTH.ushr(1)
|
||||
val HALFH: Int
|
||||
get() = HEIGHT.ushr(1)
|
||||
|
||||
/**
|
||||
* To be used with physics simulator
|
||||
*/
|
||||
val TARGET_FPS = 50
|
||||
|
||||
/**
|
||||
* To be used with render, to achieve smooth frame drawing
|
||||
|
||||
* TARGET_INTERNAL_FPS > TARGET_FPS for smooth frame drawing
|
||||
|
||||
* Must choose a value so that (1000 / VAL) is still integer
|
||||
*/
|
||||
val TARGET_INTERNAL_FPS = 100
|
||||
|
||||
/**
|
||||
* For the events depends on rendering frame (e.g. flicker on post-hit invincibility)
|
||||
*/
|
||||
var GLOBAL_RENDER_TIMER = Random().nextInt(1020) + 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val sysLang: String
|
||||
get() {
|
||||
val lan = System.getProperty("user.language")
|
||||
val country = System.getProperty("user.country")
|
||||
return lan + country
|
||||
}
|
||||
|
||||
|
||||
lateinit var appgc: AppGameContainer
|
||||
|
||||
var ingame: StateInGame? = null
|
||||
private val gameConfig = GameConfig()
|
||||
|
||||
val OSName = System.getProperty("os.name")
|
||||
val OSVersion = System.getProperty("os.version")
|
||||
lateinit var OperationSystem: String // all caps "WINDOWS, "OSX", "LINUX", "SOLARIS", "UNKNOWN"
|
||||
private set
|
||||
val isWin81: Boolean
|
||||
get() = OperationSystem == "WINDOWS" && OSVersion.toDouble() >= 8.1
|
||||
lateinit var defaultDir: String
|
||||
private set
|
||||
lateinit var defaultSaveDir: String
|
||||
private set
|
||||
|
||||
val memInUse: Long
|
||||
get() = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) shr 20
|
||||
val memTotal: Long
|
||||
get() = Runtime.getRuntime().totalMemory() shr 20
|
||||
val memXmx: Long
|
||||
get() = Runtime.getRuntime().maxMemory() shr 20
|
||||
|
||||
val environment: RunningEnvironment
|
||||
|
||||
private val localeSimple = arrayOf("de", "en", "es", "it")
|
||||
var gameLocale = "lateinit"
|
||||
set(value) {
|
||||
if (localeSimple.contains(value.substring(0..1)))
|
||||
field = value.substring(0..1)
|
||||
else
|
||||
field = value
|
||||
|
||||
(fontGame as GameFontImpl).reload()
|
||||
}
|
||||
|
||||
private val nullFont = object : Font {
|
||||
override fun getHeight(str: String?) = 0
|
||||
override fun drawString(x: Float, y: Float, text: String?) {}
|
||||
override fun drawString(x: Float, y: Float, text: String?, col: Color?) {}
|
||||
override fun drawString(x: Float, y: Float, text: String?, col: Color?, startIndex: Int, endIndex: Int) {}
|
||||
override fun getWidth(str: String?) = 0
|
||||
override fun getLineHeight() = 0
|
||||
}
|
||||
|
||||
var fontGame: Font = nullFont
|
||||
private set
|
||||
var fontSmallNumbers: Font = nullFont
|
||||
private set
|
||||
|
||||
var joypadLabelStart: Char = 0xE000.toChar() // lateinit
|
||||
var joypadLableSelect: Char = 0xE000.toChar() // lateinit
|
||||
var joypadLabelNinA: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinB: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinX: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinY: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinL: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinR: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinZL: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinZR: Char = 0xE000.toChar() // lateinit TODO
|
||||
val joypadLabelLEFT = 0xE068.toChar()
|
||||
val joypadLabelDOWN = 0xE069.toChar()
|
||||
val joypadLabelUP = 0xE06A.toChar()
|
||||
val joypadLabelRIGHT = 0xE06B.toChar()
|
||||
|
||||
// 0x0 - 0xF: Game-related
|
||||
// 0x10 - 0x1F: Config
|
||||
// 0x100 and onward: unit tests for dev
|
||||
val STATE_ID_SPLASH = 0x0
|
||||
val STATE_ID_HOME = 0x1
|
||||
val STATE_ID_GAME = 0x3
|
||||
val STATE_ID_CONFIG_CALIBRATE = 0x11
|
||||
|
||||
val STATE_ID_TEST_FONT = 0x100
|
||||
val STATE_ID_TEST_GFX = 0x101
|
||||
val STATE_ID_TEST_TTY = 0x102
|
||||
val STATE_ID_TEST_BLUR = 0x103
|
||||
val STATE_ID_TEST_SHADER = 0x104
|
||||
val STATE_ID_TEST_REFRESHRATE = 0x105
|
||||
val STATE_ID_TEST_INPUT = 0x106
|
||||
|
||||
val STATE_ID_TEST_UI1 = 0x110
|
||||
|
||||
val STATE_ID_TOOL_NOISEGEN = 0x200
|
||||
val STATE_ID_TOOL_RUMBLE_DIAGNOSIS = 0x201
|
||||
|
||||
var controller: org.lwjgl.input.Controller? = null
|
||||
private set
|
||||
val CONTROLLER_DEADZONE = 0.1f
|
||||
|
||||
/** Available CPU threads */
|
||||
val THREADS = Runtime.getRuntime().availableProcessors()
|
||||
|
||||
/**
|
||||
* If the game is multithreading.
|
||||
* True if:
|
||||
*
|
||||
* THREADS >= 2 and config "multithread" is true
|
||||
*/
|
||||
val MULTITHREAD: Boolean
|
||||
get() = THREADS >= 2 && getConfigBoolean("multithread")
|
||||
|
||||
private lateinit var configDir: String
|
||||
|
||||
/**
|
||||
* 0xAA_BB_XXXX
|
||||
* AA: Major version
|
||||
* BB: Minor version
|
||||
* XXXX: Revision (Repository commits)
|
||||
*
|
||||
* e.g. 0x02010034 can be translated as 2.1.52
|
||||
*/
|
||||
const val VERSION_RAW = 0x0002018E
|
||||
const val VERSION_STRING: String =
|
||||
"${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}"
|
||||
const val NAME = "Terrarum"
|
||||
|
||||
var delta: Int = 0
|
||||
|
||||
// these properties goes into the GameContainer
|
||||
|
||||
var previousState: Int? = null // to be used with temporary states like StateMonitorCheck
|
||||
|
||||
val systemArch = System.getProperty("os.arch")
|
||||
|
||||
private val thirtyTwoBitArchs = arrayOf("i386", "i686", "ppc", "x86", "x86_32") // I know I should Write Once, Run Everywhere; but just in case :)
|
||||
val is32Bit = thirtyTwoBitArchs.contains(systemArch)
|
||||
|
||||
lateinit var textureWhite: Image
|
||||
lateinit var textureBlack: Image
|
||||
|
||||
init {
|
||||
|
||||
// just in case
|
||||
println("[Terrarum] os.arch = $systemArch")
|
||||
|
||||
if (is32Bit) {
|
||||
println("Java is running in 32 Bit")
|
||||
}
|
||||
|
||||
joypadLabelStart = when (getConfigString("joypadlabelstyle")) {
|
||||
"nwii" -> 0xE04B.toChar() // + mark
|
||||
"logitech" -> 0xE05A.toChar() // number 10
|
||||
else -> 0xE042.toChar() // |> mark (sonyps, msxb360, generic)
|
||||
}
|
||||
joypadLableSelect = when (getConfigString("joypadlabelstyle")) {
|
||||
"nwii" -> 0xE04D.toChar() // - mark
|
||||
"logitech" -> 0xE059.toChar() // number 9
|
||||
"sonyps" -> 0xE043.toChar() // solid rectangle
|
||||
"msxb360" -> 0xE041.toChar() // <| mark
|
||||
else -> 0xE043.toChar() // solid rectangle
|
||||
}
|
||||
|
||||
|
||||
|
||||
getDefaultDirectory()
|
||||
createDirs()
|
||||
|
||||
val readFromDisk = readConfigJson()
|
||||
if (!readFromDisk) readConfigJson()
|
||||
|
||||
environment = try {
|
||||
Controllers.getController(0)
|
||||
if (getConfigString("pcgamepadenv") == "console")
|
||||
RunningEnvironment.CONSOLE
|
||||
else
|
||||
RunningEnvironment.PC
|
||||
}
|
||||
catch (e: IndexOutOfBoundsException) {
|
||||
RunningEnvironment.PC
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(SlickException::class)
|
||||
override fun initStatesList(gc: GameContainer) {
|
||||
textureWhite = Image("./assets/graphics/background_white.png")
|
||||
textureBlack = Image("./assets/graphics/background_black.png")
|
||||
|
||||
|
||||
fontGame = GameFontImpl()
|
||||
fontSmallNumbers = TinyAlphNum()
|
||||
|
||||
|
||||
gc.input.enableKeyRepeat()
|
||||
|
||||
|
||||
// get locale from config
|
||||
val gameLocaleFromConfig = gameConfig.getAsString("language") ?: sysLang
|
||||
|
||||
// if bad game locale were set, use system locale
|
||||
if (gameLocaleFromConfig.length < 2)
|
||||
gameLocale = sysLang
|
||||
else
|
||||
gameLocale = gameLocaleFromConfig
|
||||
|
||||
println("[Terrarum] Locale: " + gameLocale)
|
||||
|
||||
|
||||
|
||||
// search for real controller
|
||||
// exclude controllers with name "Mouse", "keyboard"
|
||||
val notControllerRegex = Regex("mouse|keyboard")
|
||||
try {
|
||||
// gc.input.controllerCount is unreliable
|
||||
for (i in 0..255) {
|
||||
val controllerInQuo = Controllers.getController(i)
|
||||
|
||||
println("Controller $i: ${controllerInQuo.name}")
|
||||
|
||||
// check the name
|
||||
if (!controllerInQuo.name.toLowerCase().contains(notControllerRegex)) {
|
||||
controller = controllerInQuo
|
||||
println("Controller $i selected: ${controller!!.name}")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// test acquired controller
|
||||
controller!!.getAxisValue(0)
|
||||
}
|
||||
catch (controllerDoesNotHaveAnyAxesException: java.lang.ArrayIndexOutOfBoundsException) {
|
||||
controller = null
|
||||
}
|
||||
|
||||
if (controller != null) {
|
||||
for (c in 0..controller!!.axisCount - 1) {
|
||||
controller!!.setDeadZone(c, CONTROLLER_DEADZONE)
|
||||
}
|
||||
}
|
||||
|
||||
// load languages
|
||||
Lang
|
||||
// load modules
|
||||
ModMgr
|
||||
|
||||
|
||||
gc.graphics.clear() // clean up any 'dust' in the buffer
|
||||
|
||||
//addState(StateVTTest())
|
||||
//addState(StateGraphicComputerTest())
|
||||
//addState(StateTestingLightning())
|
||||
//addState(StateSplash())
|
||||
//addState(StateMonitorCheck())
|
||||
//addState(StateFontTester())
|
||||
//addState(StateNoiseTexGen())
|
||||
//addState(StateBlurTest())
|
||||
//addState(StateShaderTest())
|
||||
//addState(StateNoiseTester())
|
||||
//addState(StateUITest())
|
||||
//addState(StateControllerRumbleTest())
|
||||
//addState(StateMidiInputTest())
|
||||
//addState(StateNewRunesTest())
|
||||
//addState(StateStutterTest())
|
||||
|
||||
|
||||
ingame = StateInGame(); addState(ingame)
|
||||
|
||||
|
||||
// foolproof
|
||||
if (stateCount < 1) {
|
||||
throw Error("Please add or un-comment addState statements")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDefaultDirectory() {
|
||||
val OS = System.getProperty("os.name").toUpperCase()
|
||||
if (OS.contains("WIN")) {
|
||||
OperationSystem = "WINDOWS"
|
||||
defaultDir = System.getenv("APPDATA") + "/Terrarum"
|
||||
}
|
||||
else if (OS.contains("OS X")) {
|
||||
OperationSystem = "OSX"
|
||||
defaultDir = System.getProperty("user.home") + "/Library/Application Support/Terrarum"
|
||||
}
|
||||
else if (OS.contains("NUX") || OS.contains("NIX")) {
|
||||
OperationSystem = "LINUX"
|
||||
defaultDir = System.getProperty("user.home") + "/.Terrarum"
|
||||
}
|
||||
else if (OS.contains("SUNOS")) {
|
||||
OperationSystem = "SOLARIS"
|
||||
defaultDir = System.getProperty("user.home") + "/.Terrarum"
|
||||
}
|
||||
else {
|
||||
OperationSystem = "UNKNOWN"
|
||||
defaultDir = System.getProperty("user.home") + "/.Terrarum"
|
||||
}
|
||||
|
||||
defaultSaveDir = defaultDir + "/Saves"
|
||||
configDir = defaultDir + "/config.json"
|
||||
|
||||
println("[Terrarum] os.name = $OSName")
|
||||
println("[Terrarum] os.version = $OSVersion")
|
||||
}
|
||||
|
||||
private fun createDirs() {
|
||||
val dirs = arrayOf(File(defaultSaveDir))
|
||||
dirs.forEach { if (!it.exists()) it.mkdirs() }
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun createConfigJson() {
|
||||
val configFile = File(configDir)
|
||||
|
||||
if (!configFile.exists() || configFile.length() == 0L) {
|
||||
JsonWriter.writeToFile(DefaultConfig.fetch(), configDir)
|
||||
}
|
||||
}
|
||||
|
||||
private fun readConfigJson(): Boolean {
|
||||
try {
|
||||
// read from disk and build config from it
|
||||
val jsonObject = JsonFetcher(configDir)
|
||||
|
||||
// make config
|
||||
jsonObject.entrySet().forEach { entry -> gameConfig[entry.key] = entry.value }
|
||||
|
||||
return true
|
||||
}
|
||||
catch (e: IOException) {
|
||||
// write default config to game dir. Call this method again to read config from it.
|
||||
try {
|
||||
createConfigJson()
|
||||
}
|
||||
catch (e1: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config from config set. If the config does not exist, default value will be returned.
|
||||
* @param key
|
||||
* *
|
||||
* @return Config from config set or default config if it does not exist.
|
||||
* *
|
||||
* @throws NullPointerException if the specified config simply does not exist.
|
||||
*/
|
||||
fun getConfigInt(key: String): Int {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonPrimitive)
|
||||
return cfg.asInt
|
||||
else
|
||||
return cfg as Int
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config from config set. If the config does not exist, default value will be returned.
|
||||
* @param key
|
||||
* *
|
||||
* @return Config from config set or default config if it does not exist.
|
||||
* *
|
||||
* @throws NullPointerException if the specified config simply does not exist.
|
||||
*/
|
||||
fun getConfigString(key: String): String {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonPrimitive)
|
||||
return cfg.asString
|
||||
else
|
||||
return cfg as String
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config from config set. If the config does not exist, default value will be returned.
|
||||
* @param key
|
||||
* *
|
||||
* @return Config from config set or default config if it does not exist.
|
||||
* *
|
||||
* @throws NullPointerException if the specified config simply does not exist.
|
||||
*/
|
||||
fun getConfigBoolean(key: String): Boolean {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonPrimitive)
|
||||
return cfg.asBoolean
|
||||
else
|
||||
return cfg as Boolean
|
||||
}
|
||||
|
||||
fun getConfigIntArray(key: String): IntArray {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonArray) {
|
||||
val jsonArray = cfg.asJsonArray
|
||||
return IntArray(jsonArray.size(), { i -> jsonArray[i].asInt })
|
||||
}
|
||||
else
|
||||
return cfg as IntArray
|
||||
}
|
||||
|
||||
private fun getConfigMaster(key: String): Any {
|
||||
var cfg: Any? = null
|
||||
try {
|
||||
cfg = gameConfig[key.toLowerCase()]!!
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
try {
|
||||
cfg = DefaultConfig.fetch()[key.toLowerCase()]
|
||||
}
|
||||
catch (e1: NullPointerException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return cfg!!
|
||||
}
|
||||
|
||||
fun setConfig(key: String, value: Any) {
|
||||
gameConfig[key] = value
|
||||
}
|
||||
|
||||
val currentSaveDir: File
|
||||
get() {
|
||||
val file = File(defaultSaveDir + "/test")
|
||||
|
||||
// failsafe?
|
||||
if (!file.exists()) file.mkdir()
|
||||
|
||||
return file // TODO TEST CODE
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for external scripts (e.g. Groovy)
|
||||
@JvmStatic fun getMouseTileX(): Int = appgc.mouseTileX
|
||||
@JvmStatic fun getMouseTileY(): Int = appgc.mouseTileY
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.library.path", "lib")
|
||||
System.setProperty("org.lwjgl.librarypath", File("lib").absolutePath)
|
||||
|
||||
try {
|
||||
Terrarum.appgc = AppGameContainer(Terrarum)
|
||||
Terrarum.appgc.setDisplayMode(Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
|
||||
if (Terrarum.RENDER_FPS > 0) {
|
||||
Terrarum.appgc.setTargetFrameRate(Terrarum.RENDER_FPS)
|
||||
}
|
||||
//Terrarum.appgc.setVSync(Terrarum.VSYNC)
|
||||
Terrarum.appgc.setMaximumLogicUpdateInterval(1000 / Terrarum.TARGET_INTERNAL_FPS) // 10 ms
|
||||
Terrarum.appgc.setMinimumLogicUpdateInterval(1000 / Terrarum.TARGET_INTERNAL_FPS - 1) // 9 ms
|
||||
|
||||
Terrarum.appgc.setMultiSample(0)
|
||||
|
||||
Terrarum.appgc.setShowFPS(false)
|
||||
|
||||
// game will run normally even if it is not focused
|
||||
Terrarum.appgc.setUpdateOnlyWhenVisible(false)
|
||||
Terrarum.appgc.alwaysRender = true
|
||||
|
||||
Terrarum.appgc.start()
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
val logger = Logger.getLogger(Terrarum::class.java.name)
|
||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss")
|
||||
val calendar = Calendar.getInstance()
|
||||
val filepath = "${Terrarum.defaultDir}/crashlog-${dateFormat.format(calendar.time)}.txt"
|
||||
val fileHandler = FileHandler(filepath)
|
||||
logger.addHandler(fileHandler)
|
||||
|
||||
val formatter = SimpleFormatter()
|
||||
fileHandler.formatter = formatter
|
||||
|
||||
//logger.info()
|
||||
println("The game has crashed!")
|
||||
println("Crash log were saved to $filepath.")
|
||||
println("================================================================================")
|
||||
logger.log(Level.SEVERE, null, ex)
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// customised blending functions //
|
||||
///////////////////////////////////
|
||||
|
||||
fun blendMul() {
|
||||
// I must say: What the fuck is wrong with you, Slick2D? Your built-it blending is just fucking wrong.
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glColorMask(true, true, true, true)
|
||||
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
}
|
||||
|
||||
fun blendNormal() {
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glColorMask(true, true, true, true)
|
||||
//GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
// semitransparent textures working as intended with this,
|
||||
// but needs further investigation in the case of:
|
||||
// TODO test blend in the situation of semitransparent over semitransparent
|
||||
GL14.glBlendFuncSeparate(
|
||||
GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, // blend func for RGB channels
|
||||
GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels
|
||||
)
|
||||
}
|
||||
|
||||
fun blendLightenOnly() {
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glColorMask(true, true, true, false)
|
||||
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE)
|
||||
GL14.glBlendEquation(GL14.GL_MAX)
|
||||
}
|
||||
|
||||
fun blendAlphaMap() {
|
||||
GL11.glDisable(GL11.GL_BLEND)
|
||||
GL11.glColorMask(false, false, false, true)
|
||||
}
|
||||
|
||||
fun blendScreen() {
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glColorMask(true, true, true, true)
|
||||
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR)
|
||||
}
|
||||
|
||||
fun blendDisable() {
|
||||
GL11.glDisable(GL11.GL_BLEND)
|
||||
}
|
||||
|
||||
object BlendMode {
|
||||
const val SCREEN = "GL_BLEND screen"
|
||||
const val MULTIPLY = "GL_BLEND multiply"
|
||||
const val NORMAL = "GL_BLEND normal"
|
||||
const val MAX = "GL_MAX"
|
||||
|
||||
fun resolve(mode: String) {
|
||||
when (mode) {
|
||||
SCREEN -> blendScreen()
|
||||
MULTIPLY -> blendMul()
|
||||
NORMAL -> blendNormal()
|
||||
MAX -> blendLightenOnly()
|
||||
else -> throw Error("Unknown blend mode: $mode")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class RunningEnvironment {
|
||||
PC, CONSOLE, MOBILE
|
||||
}
|
||||
|
||||
/** @return Intarray(R, G, B, A) */
|
||||
fun Texture.getPixel(x: Int, y: Int): IntArray {
|
||||
val textureWidth = this.textureWidth
|
||||
val hasAlpha = this.hasAlpha()
|
||||
|
||||
val offset = (if (hasAlpha) 4 else 3) * (textureWidth * y + x) // 4: # of channels (RGBA)
|
||||
|
||||
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
|
||||
return intArrayOf(
|
||||
this.textureData[offset].toUint(),
|
||||
this.textureData[offset + 1].toUint(),
|
||||
this.textureData[offset + 2].toUint(),
|
||||
if (hasAlpha)
|
||||
this.textureData[offset + 3].toUint()
|
||||
else 255
|
||||
)
|
||||
}
|
||||
else {
|
||||
return intArrayOf(
|
||||
this.textureData[offset + 2].toUint(),
|
||||
this.textureData[offset + 1].toUint(),
|
||||
this.textureData[offset].toUint(),
|
||||
if (hasAlpha)
|
||||
this.textureData[offset + 3].toUint()
|
||||
else 255
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** @return Intarray(R, G, B, A) */
|
||||
fun Image.getPixel(x: Int, y: Int) = this.texture.getPixel(x, y)
|
||||
|
||||
fun Color.toInt() = redByte.shl(16) or greenByte.shl(8) or blueByte
|
||||
fun Color.to10bit() = redByte.shl(20) or greenByte.shl(10) or blueByte
|
||||
|
||||
infix fun Color.screen(other: Color) = Color(
|
||||
1f - (1f - this.r) * (1f - other.r),
|
||||
1f - (1f - this.g) * (1f - other.g),
|
||||
1f - (1f - this.b) * (1f - other.b),
|
||||
1f - (1f - this.a) * (1f - other.a)
|
||||
)
|
||||
infix fun Color.mul(other: Color) = Color( // don't turn into an operator!
|
||||
this.r * other.r,
|
||||
this.g * other.g,
|
||||
this.b * other.b,
|
||||
this.a * other.a
|
||||
)
|
||||
infix fun Color.minus(other: Color) = Color( // don't turn into an operator!
|
||||
this.r - other.r,
|
||||
this.g - other.g,
|
||||
this.b - other.b,
|
||||
this.a - other.a
|
||||
)
|
||||
|
||||
fun Int.toHex() = this.toLong().and(0xFFFFFFFF).toString(16).padStart(8, '0').toUpperCase()
|
||||
fun Long.toHex() = {
|
||||
val sb = StringBuilder()
|
||||
(0..16).forEach {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,610 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Screen
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.GL20
|
||||
import com.badlogic.gdx.graphics.GL30
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.Batch
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonPrimitive
|
||||
import net.torvald.terrarum.gameactors.ActorWithPhysics.Companion.TILE_SIZE
|
||||
import net.torvald.terrarum.gamecontroller.GameController
|
||||
import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.utils.JsonWriter
|
||||
import net.torvald.terrarum.worlddrawer.RGB10
|
||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import org.lwjgl.input.Controllers
|
||||
import org.lwjgl.opengl.GL11
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-15.
|
||||
*/
|
||||
object TerrarumGDX {
|
||||
}
|
||||
|
||||
const val GAME_NAME = "Terrarum"
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val config = LwjglApplicationConfiguration()
|
||||
config.foregroundFPS = TerrarumGDX.RENDER_FPS
|
||||
config.backgroundFPS = TerrarumGDX.RENDER_FPS
|
||||
config.vSyncEnabled = true
|
||||
config.resizable = false
|
||||
config.width = 1072
|
||||
config.height = 742
|
||||
config.title = GAME_NAME
|
||||
|
||||
LwjglApplication(TerrarumGDX, config)
|
||||
}
|
||||
|
||||
|
||||
|
||||
typealias RGBA8888 = Int
|
||||
|
||||
object TerrarumGDX : ApplicationAdapter() {
|
||||
|
||||
lateinit var batch: SpriteBatch
|
||||
lateinit var shapeRender: ShapeRenderer // DO NOT USE!! for very limited applications e.g. WeatherMixer
|
||||
inline fun inShapeRenderer(shapeRendererType: ShapeRenderer.ShapeType = ShapeRenderer.ShapeType.Filled, action: (ShapeRenderer) -> Unit) {
|
||||
shapeRender.begin(shapeRendererType)
|
||||
action(shapeRender)
|
||||
shapeRender.end()
|
||||
}
|
||||
|
||||
|
||||
lateinit var orthoLineTex2px: Texture
|
||||
lateinit var orthoLineTex3px: Texture
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// GLOBAL IMMUTABLE CONFIGS //
|
||||
//////////////////////////////
|
||||
|
||||
val RENDER_FPS = getConfigInt("displayfps")
|
||||
val USE_VSYNC = getConfigBoolean("usevsync")
|
||||
var VSYNC = USE_VSYNC
|
||||
val VSYNC_TRIGGER_THRESHOLD = 56
|
||||
|
||||
inline val HALFW: Int
|
||||
get() = Gdx.graphics.width.ushr(1)
|
||||
inline val HALFH: Int
|
||||
get() = Gdx.graphics.height.ushr(1)
|
||||
|
||||
/**
|
||||
* To be used with physics simulator
|
||||
*/
|
||||
val TARGET_FPS = 50
|
||||
|
||||
/**
|
||||
* To be used with render, to achieve smooth frame drawing
|
||||
|
||||
* TARGET_INTERNAL_FPS > TARGET_FPS for smooth frame drawing
|
||||
|
||||
* Must choose a value so that (1000 / VAL) is still integer
|
||||
*/
|
||||
val TARGET_INTERNAL_FPS = 100
|
||||
|
||||
|
||||
/**
|
||||
* For the events depends on rendering frame (e.g. flicker on post-hit invincibility)
|
||||
*/
|
||||
var GLOBAL_RENDER_TIMER = Random().nextInt(1020) + 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val sysLang: String
|
||||
get() {
|
||||
val lan = System.getProperty("user.language")
|
||||
val country = System.getProperty("user.country")
|
||||
return lan + country
|
||||
}
|
||||
|
||||
lateinit var currentScreen: Screen
|
||||
var previousScreen: Screen? = null // to be used with temporary states like StateMonitorCheck
|
||||
|
||||
|
||||
var ingame: StateInGameGDX? = null
|
||||
private val gameConfig = GameConfig()
|
||||
|
||||
val OSName = System.getProperty("os.name")
|
||||
val OSVersion = System.getProperty("os.version")
|
||||
lateinit var OperationSystem: String // all caps "WINDOWS, "OSX", "LINUX", "SOLARIS", "UNKNOWN"
|
||||
private set
|
||||
lateinit var defaultDir: String
|
||||
private set
|
||||
lateinit var defaultSaveDir: String
|
||||
private set
|
||||
|
||||
val memInUse: Long
|
||||
get() = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) shr 20
|
||||
val memTotal: Long
|
||||
get() = Runtime.getRuntime().totalMemory() shr 20
|
||||
val memXmx: Long
|
||||
get() = Runtime.getRuntime().maxMemory() shr 20
|
||||
|
||||
val environment: RunningEnvironment
|
||||
|
||||
private val localeSimple = arrayOf("de", "en", "es", "it")
|
||||
var gameLocale = "lateinit"
|
||||
set(value) {
|
||||
if (localeSimple.contains(value.substring(0..1)))
|
||||
field = value.substring(0..1)
|
||||
else
|
||||
field = value
|
||||
|
||||
fontGame.reload(value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
lateinit var fontGame: GameFontBase
|
||||
lateinit var fontSmallNumbers: BitmapFont
|
||||
|
||||
var joypadLabelStart: Char = 0xE000.toChar() // lateinit
|
||||
var joypadLableSelect: Char = 0xE000.toChar() // lateinit
|
||||
var joypadLabelNinA: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinB: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinX: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinY: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinL: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinR: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinZL: Char = 0xE000.toChar() // lateinit TODO
|
||||
var joypadLabelNinZR: Char = 0xE000.toChar() // lateinit TODO
|
||||
val joypadLabelLEFT = 0xE068.toChar()
|
||||
val joypadLabelDOWN = 0xE069.toChar()
|
||||
val joypadLabelUP = 0xE06A.toChar()
|
||||
val joypadLabelRIGHT = 0xE06B.toChar()
|
||||
|
||||
// 0x0 - 0xF: Game-related
|
||||
// 0x10 - 0x1F: Config
|
||||
// 0x100 and onward: unit tests for dev
|
||||
val STATE_ID_SPLASH = 0x0
|
||||
val STATE_ID_HOME = 0x1
|
||||
val STATE_ID_GAME = 0x3
|
||||
val STATE_ID_CONFIG_CALIBRATE = 0x11
|
||||
|
||||
val STATE_ID_TEST_FONT = 0x100
|
||||
val STATE_ID_TEST_GFX = 0x101
|
||||
val STATE_ID_TEST_TTY = 0x102
|
||||
val STATE_ID_TEST_BLUR = 0x103
|
||||
val STATE_ID_TEST_SHADER = 0x104
|
||||
val STATE_ID_TEST_REFRESHRATE = 0x105
|
||||
val STATE_ID_TEST_INPUT = 0x106
|
||||
|
||||
val STATE_ID_TEST_UI1 = 0x110
|
||||
|
||||
val STATE_ID_TOOL_NOISEGEN = 0x200
|
||||
val STATE_ID_TOOL_RUMBLE_DIAGNOSIS = 0x201
|
||||
|
||||
var controller: org.lwjgl.input.Controller? = null
|
||||
private set
|
||||
val CONTROLLER_DEADZONE = 0.1f
|
||||
|
||||
/** Available CPU threads */
|
||||
val THREADS = Runtime.getRuntime().availableProcessors()
|
||||
|
||||
/**
|
||||
* If the game is multithreading.
|
||||
* True if:
|
||||
*
|
||||
* THREADS >= 2 and config "multithread" is true
|
||||
*/
|
||||
val MULTITHREAD: Boolean
|
||||
get() = THREADS >= 2 && getConfigBoolean("multithread")
|
||||
|
||||
private lateinit var configDir: String
|
||||
|
||||
/**
|
||||
* 0xAA_BB_XXXX
|
||||
* AA: Major version
|
||||
* BB: Minor version
|
||||
* XXXX: Revision (Repository commits)
|
||||
*
|
||||
* e.g. 0x02010034 can be translated as 2.1.52
|
||||
*/
|
||||
const val VERSION_RAW = 0x00_02_018E
|
||||
const val VERSION_STRING: String =
|
||||
"${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}"
|
||||
const val NAME = "Terrarum"
|
||||
|
||||
|
||||
val systemArch = System.getProperty("os.arch")
|
||||
|
||||
val is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64")
|
||||
|
||||
|
||||
init {
|
||||
println("[Terrarum] os.arch = $systemArch") // debug info
|
||||
|
||||
if (is32BitJVM) {
|
||||
println("32 Bit JVM detected")
|
||||
}
|
||||
|
||||
joypadLabelStart = when (getConfigString("joypadlabelstyle")) {
|
||||
"nwii" -> 0xE04B.toChar() // + mark
|
||||
"logitech" -> 0xE05A.toChar() // number 10
|
||||
else -> 0xE042.toChar() // |> mark (sonyps, msxb360, generic)
|
||||
}
|
||||
joypadLableSelect = when (getConfigString("joypadlabelstyle")) {
|
||||
"nwii" -> 0xE04D.toChar() // - mark
|
||||
"logitech" -> 0xE059.toChar() // number 9
|
||||
"sonyps" -> 0xE043.toChar() // solid rectangle
|
||||
"msxb360" -> 0xE041.toChar() // <| mark
|
||||
else -> 0xE043.toChar() // solid rectangle
|
||||
}
|
||||
|
||||
|
||||
|
||||
getDefaultDirectory()
|
||||
createDirs()
|
||||
|
||||
val readFromDisk = readConfigJson()
|
||||
if (!readFromDisk) readConfigJson()
|
||||
|
||||
environment = try {
|
||||
Controllers.getController(0) // test if controller exists
|
||||
if (getConfigString("pcgamepadenv") == "console")
|
||||
RunningEnvironment.CONSOLE
|
||||
else
|
||||
RunningEnvironment.PC
|
||||
}
|
||||
catch (e: IndexOutOfBoundsException) {
|
||||
RunningEnvironment.PC
|
||||
}
|
||||
}
|
||||
|
||||
override fun create() {
|
||||
TextureRegionPack.globalFlipY = true // !! TO MAKE LEGACY CODE RENDER ON ITS POSITION !!
|
||||
Gdx.graphics.isContinuousRendering = true
|
||||
|
||||
batch = SpriteBatch()
|
||||
shapeRender = ShapeRenderer()
|
||||
|
||||
orthoLineTex2px = Texture("assets/graphics/ortho_line_tex_2px.tga")
|
||||
orthoLineTex3px = Texture("assets/graphics/ortho_line_tex_3px.tga")
|
||||
|
||||
|
||||
fontGame = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", flipY = true)
|
||||
fontSmallNumbers = TinyAlphNum
|
||||
|
||||
|
||||
|
||||
|
||||
ingame = StateInGameGDX(batch)
|
||||
ingame!!.enter()
|
||||
currentScreen = ingame as Screen
|
||||
}
|
||||
|
||||
override fun render() {
|
||||
currentScreen.render(Gdx.graphics.deltaTime)
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
currentScreen.pause()
|
||||
}
|
||||
|
||||
override fun resume() {
|
||||
currentScreen.resume()
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
currentScreen.dispose()
|
||||
fontGame.dispose()
|
||||
fontSmallNumbers.dispose()
|
||||
//dispose any other resources used in this level
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
currentScreen.resize(width, height)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private fun getDefaultDirectory() {
|
||||
val OS = System.getProperty("os.name").toUpperCase()
|
||||
if (OS.contains("WIN")) {
|
||||
OperationSystem = "WINDOWS"
|
||||
defaultDir = System.getenv("APPDATA") + "/Terrarum"
|
||||
}
|
||||
else if (OS.contains("OS X")) {
|
||||
OperationSystem = "OSX"
|
||||
defaultDir = System.getProperty("user.home") + "/Library/Application Support/Terrarum"
|
||||
}
|
||||
else if (OS.contains("NUX") || OS.contains("NIX")) {
|
||||
OperationSystem = "LINUX"
|
||||
defaultDir = System.getProperty("user.home") + "/.Terrarum"
|
||||
}
|
||||
else if (OS.contains("SUNOS")) {
|
||||
OperationSystem = "SOLARIS"
|
||||
defaultDir = System.getProperty("user.home") + "/.Terrarum"
|
||||
}
|
||||
else {
|
||||
OperationSystem = "UNKNOWN"
|
||||
defaultDir = System.getProperty("user.home") + "/.Terrarum"
|
||||
}
|
||||
|
||||
defaultSaveDir = defaultDir + "/Saves"
|
||||
configDir = defaultDir + "/config.json"
|
||||
|
||||
println("[Terrarum] os.name = $OSName")
|
||||
println("[Terrarum] os.version = $OSVersion")
|
||||
}
|
||||
|
||||
private fun createDirs() {
|
||||
val dirs = arrayOf(File(defaultSaveDir))
|
||||
dirs.forEach { if (!it.exists()) it.mkdirs() }
|
||||
}
|
||||
|
||||
private fun createConfigJson() {
|
||||
val configFile = File(configDir)
|
||||
|
||||
if (!configFile.exists() || configFile.length() == 0L) {
|
||||
JsonWriter.writeToFile(DefaultConfig.fetch(), configDir)
|
||||
}
|
||||
}
|
||||
|
||||
private fun readConfigJson(): Boolean {
|
||||
try {
|
||||
// read from disk and build config from it
|
||||
val jsonObject = JsonFetcher(configDir)
|
||||
|
||||
// make config
|
||||
jsonObject.entrySet().forEach { entry -> gameConfig[entry.key] = entry.value }
|
||||
|
||||
return true
|
||||
}
|
||||
catch (e: IOException) {
|
||||
// write default config to game dir. Call this method again to read config from it.
|
||||
try {
|
||||
createConfigJson()
|
||||
}
|
||||
catch (e1: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config from config set. If the config does not exist, default value will be returned.
|
||||
* @param key
|
||||
* *
|
||||
* @return Config from config set or default config if it does not exist.
|
||||
* *
|
||||
* @throws NullPointerException if the specified config simply does not exist.
|
||||
*/
|
||||
fun getConfigInt(key: String): Int {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonPrimitive)
|
||||
return cfg.asInt
|
||||
else
|
||||
return cfg as Int
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config from config set. If the config does not exist, default value will be returned.
|
||||
* @param key
|
||||
* *
|
||||
* @return Config from config set or default config if it does not exist.
|
||||
* *
|
||||
* @throws NullPointerException if the specified config simply does not exist.
|
||||
*/
|
||||
fun getConfigString(key: String): String {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonPrimitive)
|
||||
return cfg.asString
|
||||
else
|
||||
return cfg as String
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config from config set. If the config does not exist, default value will be returned.
|
||||
* @param key
|
||||
* *
|
||||
* @return Config from config set or default config if it does not exist.
|
||||
* *
|
||||
* @throws NullPointerException if the specified config simply does not exist.
|
||||
*/
|
||||
fun getConfigBoolean(key: String): Boolean {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonPrimitive)
|
||||
return cfg.asBoolean
|
||||
else
|
||||
return cfg as Boolean
|
||||
}
|
||||
|
||||
fun getConfigIntArray(key: String): IntArray {
|
||||
val cfg = getConfigMaster(key)
|
||||
if (cfg is JsonArray) {
|
||||
val jsonArray = cfg.asJsonArray
|
||||
return IntArray(jsonArray.size(), { i -> jsonArray[i].asInt })
|
||||
}
|
||||
else
|
||||
return cfg as IntArray
|
||||
}
|
||||
|
||||
private fun getConfigMaster(key: String): Any {
|
||||
var cfg: Any? = null
|
||||
try {
|
||||
cfg = gameConfig[key.toLowerCase()]!!
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
try {
|
||||
cfg = DefaultConfig.fetch()[key.toLowerCase()]
|
||||
}
|
||||
catch (e1: NullPointerException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return cfg!!
|
||||
}
|
||||
|
||||
fun setConfig(key: String, value: Any) {
|
||||
gameConfig[key] = value
|
||||
}
|
||||
|
||||
val currentSaveDir: File
|
||||
get() {
|
||||
val file = File(defaultSaveDir + "/test")
|
||||
|
||||
// failsafe?
|
||||
if (!file.exists()) file.mkdir()
|
||||
|
||||
return file // TODO TEST CODE
|
||||
}
|
||||
|
||||
inline val mouseX: Double
|
||||
get() = GameController.mouseX.toDouble()
|
||||
inline val mouseY: Double
|
||||
get() = GameController.mouseY.toDouble()
|
||||
@JvmStatic inline val mouseTileX: Int
|
||||
get() = mouseX.toInt() / TILE_SIZE
|
||||
@JvmStatic inline val mouseTileY: Int
|
||||
get() = mouseY.toInt() / TILE_SIZE
|
||||
inline val mouseScreenX: Int
|
||||
get() = Gdx.input.x
|
||||
inline val mouseScreenY: Int
|
||||
get() = Gdx.input.y
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
inline fun Batch.inUse(action: (Batch) -> Unit) {
|
||||
this.begin()
|
||||
action(this)
|
||||
this.end()
|
||||
}
|
||||
|
||||
inline fun ShapeRenderer.inUse(shapeRendererType: ShapeRenderer.ShapeType = ShapeRenderer.ShapeType.Filled, action: (ShapeRenderer) -> Unit) {
|
||||
this.begin(shapeRendererType)
|
||||
action(this)
|
||||
this.end()
|
||||
}
|
||||
|
||||
/** Use Batch inside of it! */
|
||||
inline fun FrameBuffer.inAction(action: (FrameBuffer) -> Unit) {
|
||||
this.begin()
|
||||
action(this)
|
||||
this.end()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ShapeRenderer alternative for rects
|
||||
inline fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) {
|
||||
this.draw(net.torvald.terrarum.TerrarumGDX.orthoLineTex2px, x, y, w, h)
|
||||
}
|
||||
inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, p2: Float, thickness: Float, isVertical: Boolean) {
|
||||
if (!isVertical)
|
||||
this.fillRect(x, y, p2 - x, thickness)
|
||||
else
|
||||
this.fillRect(x, y, thickness, p2 - y)
|
||||
}
|
||||
|
||||
|
||||
|
||||
infix fun Color.mul(other: Color): Color = this.mul(other)
|
||||
|
||||
|
||||
|
||||
inline fun Color.toRGB10(): RGB10 {
|
||||
val bits = this.toIntBits() // ABGR
|
||||
// 0bxxRRRRRRRRRRGGGGGGGGGGBBBBBBBBBB
|
||||
// 0bAAAAAAAABBBBBBBBGGGGGGGGRRRRRRRR
|
||||
return bits.and(0x0000FF).shl(20) or bits.and(0x00FF00).shl(2) or bits.and(0xFF0000).ushr(16)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun blendMul() {
|
||||
// I must say: What the fuck is wrong with you, Slick2D? Your built-it blending is just fucking wrong.
|
||||
TerrarumGDX.batch.enableBlending()
|
||||
TerrarumGDX.batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
|
||||
}
|
||||
|
||||
fun blendNormal() {
|
||||
TerrarumGDX.batch.enableBlending()
|
||||
TerrarumGDX.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
|
||||
}
|
||||
|
||||
fun blendLightenOnly() {
|
||||
TerrarumGDX.batch.enableBlending()
|
||||
TerrarumGDX.batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE)
|
||||
Gdx.gl.glBlendEquation(GL30.GL_MAX) // batch.flush does not touch blend equation
|
||||
}
|
||||
|
||||
fun blendScreen() {
|
||||
TerrarumGDX.batch.enableBlending()
|
||||
TerrarumGDX.batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR)
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
|
||||
}
|
||||
|
||||
object BlendMode {
|
||||
const val SCREEN = "GL_BLEND screen"
|
||||
const val MULTIPLY = "GL_BLEND multiply"
|
||||
const val NORMAL = "GL_BLEND normal"
|
||||
const val MAX = "GL_MAX"
|
||||
|
||||
fun resolve(mode: String) {
|
||||
when (mode) {
|
||||
SCREEN -> blendScreen()
|
||||
MULTIPLY -> blendMul()
|
||||
NORMAL -> blendNormal()
|
||||
MAX -> blendLightenOnly()
|
||||
else -> throw Error("Unknown blend mode: $mode")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class RunningEnvironment {
|
||||
PC, CONSOLE, MOBILE
|
||||
}
|
||||
|
||||
infix fun Color.screen(other: Color) = Color(
|
||||
1f - (1f - this.r) * (1f - other.r),
|
||||
1f - (1f - this.g) * (1f - other.g),
|
||||
1f - (1f - this.b) * (1f - other.b),
|
||||
1f - (1f - this.a) * (1f - other.a)
|
||||
)
|
||||
|
||||
infix fun Color.minus(other: Color) = Color( // don't turn into an operator!
|
||||
this.r - other.r,
|
||||
this.g - other.g,
|
||||
this.b - other.b,
|
||||
this.a - other.a
|
||||
)
|
||||
|
||||
fun Int.toHex() = this.toLong().and(0xFFFFFFFF).toString(16).padStart(8, '0').toUpperCase()
|
||||
fun Long.toHex() = {
|
||||
val sb = StringBuilder()
|
||||
(0..16).forEach {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestTestTest : ApplicationAdapter() {
|
||||
batch = SpriteBatch()
|
||||
img = Texture("assets/test_texture.tga")
|
||||
|
||||
gameFont = GameFontBase("assets/graphics/fonts")
|
||||
gameFont = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap")
|
||||
//gameFont = BitmapFont()
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.colourutil.CIELabUtil.darkerLab
|
||||
import net.torvald.terrarum.gamecontroller.Key
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.ui.UIInventory
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import net.torvald.terrarum.ui.UIItemTextButton
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
/***
|
||||
* Note that the UI will not render if either item or itemImage is null.
|
||||
@@ -23,12 +23,12 @@ class UIItemInventoryElem(
|
||||
override val width: Int,
|
||||
var item: GameItem?,
|
||||
var amount: Int,
|
||||
var itemImage: Image?,
|
||||
val mouseOverTextCol: Color = Color(0xfff066),
|
||||
val mouseoverBackCol: Color = Color(0,0,0,0),
|
||||
var itemImage: TextureRegion?,
|
||||
val mouseOverTextCol: Color = Color(0xfff066_ff.toInt()),
|
||||
val mouseoverBackCol: Color = Color(0),
|
||||
val mouseoverBackBlendMode: String = BlendMode.NORMAL,
|
||||
val inactiveTextCol: Color = UIItemTextButton.defaultInactiveCol,
|
||||
val backCol: Color = Color(0,0,0,0),
|
||||
val backCol: Color = Color(0),
|
||||
val backBlendMode: String = BlendMode.NORMAL,
|
||||
var quickslot: Int? = null,
|
||||
var equippedSlot: Int? = null,
|
||||
@@ -45,7 +45,7 @@ class UIItemInventoryElem(
|
||||
override val height = UIItemInventoryElem.height
|
||||
|
||||
private val imgOffset: Float
|
||||
get() = (this.height - itemImage!!.height).div(2).toFloat() // to snap to the pixel grid
|
||||
get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid
|
||||
private val textOffsetX = 50f
|
||||
private val textOffsetY = 8f
|
||||
|
||||
@@ -56,7 +56,7 @@ class UIItemInventoryElem(
|
||||
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
override fun update(delta: Float) {
|
||||
if (item != null) {
|
||||
|
||||
}
|
||||
@@ -64,22 +64,21 @@ class UIItemInventoryElem(
|
||||
|
||||
private val fwsp = 0x3000.toChar()
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
g.font = Terrarum.fontGame
|
||||
override fun render(batch: SpriteBatch) {
|
||||
|
||||
// mouseover background
|
||||
if (item != null || drawBackOnNull) {
|
||||
// do not highlight even if drawBackOnNull is true
|
||||
if (mouseUp && item != null) {
|
||||
BlendMode.resolve(mouseoverBackBlendMode)
|
||||
g.color = mouseoverBackCol
|
||||
batch.color = mouseoverBackCol
|
||||
}
|
||||
// if drawBackOnNull, just draw background
|
||||
else {
|
||||
BlendMode.resolve(backBlendMode)
|
||||
g.color = backCol
|
||||
batch.color = backCol
|
||||
}
|
||||
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
|
||||
|
||||
@@ -87,12 +86,12 @@ class UIItemInventoryElem(
|
||||
blendNormal()
|
||||
|
||||
// item image
|
||||
g.drawImage(itemImage!!, posX + imgOffset, posY + imgOffset)
|
||||
batch.draw(itemImage, posX + imgOffset, posY + imgOffset)
|
||||
|
||||
// if mouse is over, text lights up
|
||||
// this one-liner sets color
|
||||
g.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol
|
||||
g.drawString(
|
||||
batch.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol
|
||||
TerrarumGDX.fontGame.draw(batch,
|
||||
//"$item" + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") +
|
||||
item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") +
|
||||
(if (equippedSlot != null) " ${0xE081.toChar()}\$$equippedSlot" else ""),
|
||||
@@ -105,28 +104,27 @@ class UIItemInventoryElem(
|
||||
val barFullLen = (width - 8f) - textOffsetX
|
||||
val barOffset = posX + textOffsetX
|
||||
if (item!!.maxDurability > 0.0) {
|
||||
g.color = durabilityBack
|
||||
g.lineWidth = 3f
|
||||
g.drawLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen, posY + durabilityBarOffY)
|
||||
g.color = durabilityCol
|
||||
g.drawLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen * (item!!.durability / item!!.maxDurability), posY + durabilityBarOffY)
|
||||
batch.color = durabilityBack
|
||||
batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen, 3f, false)
|
||||
batch.color = durabilityCol
|
||||
batch.drawStraightLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen * (item!!.durability / item!!.maxDurability), 3f, false)
|
||||
}
|
||||
|
||||
|
||||
// quickslot marker (TEMPORARY UNTIL WE GET BETTER DESIGN)
|
||||
if (quickslot != null) {
|
||||
val label = quickslot!!.plus(0xE010).toChar()
|
||||
val labelW = g.font.getWidth("$label")
|
||||
g.color = Color.white
|
||||
g.drawString("$label", barOffset + barFullLen - labelW, posY + textOffsetY)
|
||||
val labelW = TerrarumGDX.fontGame.getWidth("$label")
|
||||
batch.color = Color.WHITE
|
||||
TerrarumGDX.fontGame.draw(batch, "$label", barOffset + barFullLen - labelW, posY + textOffsetY)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
if (item != null && Terrarum.ingame != null && key in Key.NUM_1..Key.NUM_0) {
|
||||
val inventory = Terrarum.ingame!!.player?.inventory
|
||||
if (item != null && TerrarumGDX.ingame != null && key in Key.NUM_1..Key.NUM_0) {
|
||||
val inventory = TerrarumGDX.ingame!!.player?.inventory
|
||||
val slot = key - Key.NUM_1
|
||||
val currentSlotItem = inventory?.getQuickBar(slot)
|
||||
|
||||
@@ -159,11 +157,11 @@ class UIItemInventoryElem(
|
||||
}
|
||||
|
||||
override fun mousePressed(button: Int, x: Int, y: Int) {
|
||||
if (item != null && Terrarum.ingame != null) {
|
||||
if (item != null && TerrarumGDX.ingame != null) {
|
||||
|
||||
// equip da shit
|
||||
val itemEquipSlot = item!!.equipPosition
|
||||
val player = Terrarum.ingame!!.player
|
||||
val player = TerrarumGDX.ingame!!.player
|
||||
|
||||
if (item != player?.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it
|
||||
player?.equipItem(item!!)
|
||||
@@ -187,4 +185,4 @@ class UIItemInventoryElem(
|
||||
|
||||
override fun controllerButtonReleased(controller: Int, button: Int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package net.torvald.terrarum.audio
|
||||
|
||||
import org.lwjgl.BufferUtils
|
||||
import org.lwjgl.openal.AL10
|
||||
import org.newdawn.slick.Music
|
||||
import org.newdawn.slick.openal.Audio
|
||||
import org.newdawn.slick.openal.AudioImpl
|
||||
import org.newdawn.slick.openal.MODSound
|
||||
import org.newdawn.slick.openal.StreamSound
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-07-08.
|
||||
*/
|
||||
object AudioMixer {
|
||||
const val TRACK_COUNT = 32
|
||||
|
||||
const val TRACK_AMBIENT_ONE = 0 // music track one
|
||||
const val TRACK_AMBIENT_ONE_NEXT = 1 // music track two
|
||||
const val TRACK_AMBIENT_TWO = 2 // music track three
|
||||
const val TRACK_AMBIENT_TWO_NEXT = 3 // music track four
|
||||
|
||||
const val TRACK_UI_ONE = 8
|
||||
const val TRACK_UI_TWO = 9
|
||||
|
||||
const val TRACK_SFX_START = 16
|
||||
const val TRACK_SFX_END = 31
|
||||
|
||||
val tracks = ArrayList<Int>(TRACK_COUNT) // stores index of ALSource
|
||||
|
||||
init {
|
||||
tracks[TRACK_AMBIENT_ONE]
|
||||
}
|
||||
|
||||
fun getAudio(track: Int) = tracks[track]
|
||||
|
||||
fun play(channel: Int) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue an SFX to any empty SFX track and play it.
|
||||
*/
|
||||
fun queueSfx(audio: Audio) {
|
||||
|
||||
}
|
||||
|
||||
fun update(delta: Int) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MixerTrack(val audio: Audio, var volume: Float, var pan: Float) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.torvald.terrarum.audio
|
||||
|
||||
import org.newdawn.slick.openal.Audio
|
||||
import org.newdawn.slick.openal.AudioLoader
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.audio.Music
|
||||
import com.badlogic.gdx.audio.Sound
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -12,24 +12,21 @@ import java.util.*
|
||||
object AudioResourceLibrary {
|
||||
|
||||
// will play as music
|
||||
val ambientsForest = ArrayList<Audio>()
|
||||
val ambientsMeadow = ArrayList<Audio>()
|
||||
val ambientsWindy = ArrayList<Audio>()
|
||||
val ambientsWoods = ArrayList<Audio>()
|
||||
val ambientsForest = ArrayList<Music>()
|
||||
val ambientsMeadow = ArrayList<Music>()
|
||||
val ambientsWindy = ArrayList<Music>()
|
||||
val ambientsWoods = ArrayList<Music>()
|
||||
|
||||
// will play as sound effect
|
||||
val crickets = ArrayList<Audio>()
|
||||
val crickets = ArrayList<Sound>()
|
||||
|
||||
init {
|
||||
ambientsForest.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_forest_01.ogg").toURI().toURL()))
|
||||
ambientsForest.add(Gdx.audio.newMusic(ModMgr.getGdxFile("basegame", "sounds/ambient/ambient_forest_01.ogg")))
|
||||
ambientsMeadow.add(Gdx.audio.newMusic(ModMgr.getGdxFile("basegame", "sounds/ambient/ambient_meadow_01.ogg")))
|
||||
ambientsWindy.add(Gdx.audio.newMusic(ModMgr.getGdxFile("basegame", "sounds/ambient/ambient_windy_01.ogg")))
|
||||
ambientsWoods.add(Gdx.audio.newMusic(ModMgr.getGdxFile("basegame", "sounds/ambient/ambient_woods_01.ogg")))
|
||||
|
||||
ambientsMeadow.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_meadow_01.ogg").toURI().toURL()))
|
||||
|
||||
ambientsWindy.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_windy_01.ogg").toURI().toURL()))
|
||||
|
||||
ambientsWoods.add(AudioLoader.getStreamingAudio("OGG", File("./assets/sounds/ambient/ambient_woods_01.ogg").toURI().toURL()))
|
||||
|
||||
crickets.add(AudioLoader.getAudio("OGG", FileInputStream("./assets/sounds/ambient/crickets_01.ogg")))
|
||||
crickets.add(AudioLoader.getAudio("OGG", FileInputStream("./assets/sounds/ambient/crickets_02.ogg")))
|
||||
crickets.add(Gdx.audio.newSound(ModMgr.getGdxFile("basegame", "sounds/ambient/crickets_01.ogg")))
|
||||
crickets.add(Gdx.audio.newSound(ModMgr.getGdxFile("basegame", "sounds/ambient/crickets_02.ogg")))
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,31 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.TerrarumGDX
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.toInt
|
||||
import net.torvald.terrarum.toRGB10
|
||||
import net.torvald.terrarum.weather.WeatherMixer
|
||||
import net.torvald.terrarum.worlddrawer.RGB10
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-06-16.
|
||||
*/
|
||||
object BlockPropUtil {
|
||||
var flickerFuncX: Millisec = 0 // in milliseconds; saves current status (time) of func
|
||||
val flickerFuncDomain: Millisec = 100 // time between two noise sample, in milliseconds
|
||||
var flickerFuncX: Second = 0f // saves current status (time) of func
|
||||
val flickerFuncDomain: Second = 0.1f // time between two noise sample
|
||||
val flickerFuncRange = 0.012f // intensity [0, 1]
|
||||
|
||||
var breathFuncX = 0
|
||||
var breathFuncX = 0f
|
||||
val breathRange = 0.02f
|
||||
val breathCycleDuration: Millisec = 2000 // in milliseconds
|
||||
val breathCycleDuration: Second = 2f
|
||||
|
||||
var pulsateFuncX = 0
|
||||
var pulsateFuncX = 0f
|
||||
val pulsateRange = 0.034f
|
||||
val pulsateCycleDuration: Millisec = 500 // in milliseconds
|
||||
val pulsateCycleDuration: Second = 0.5f
|
||||
|
||||
val random = HQRNG()
|
||||
|
||||
@@ -36,7 +38,7 @@ object BlockPropUtil {
|
||||
|
||||
}
|
||||
|
||||
private fun getTorchFlicker(baseLum: Int): Int {
|
||||
private fun getTorchFlicker(baseLum: Int): RGB10 {
|
||||
val funcY = FastMath.interpolateCatmullRom(0.0f, flickerFuncX.toFloat() / flickerFuncDomain,
|
||||
flickerP0, flickerP1, flickerP2, flickerP3
|
||||
)
|
||||
@@ -61,10 +63,10 @@ object BlockPropUtil {
|
||||
*/
|
||||
internal fun dynamicLumFuncTickClock() {
|
||||
// FPS-time compensation
|
||||
if (Terrarum.appgc.fps > 0) {
|
||||
flickerFuncX += 1000 / Terrarum.appgc.fps
|
||||
breathFuncX += 1000 / Terrarum.appgc.fps
|
||||
pulsateFuncX += 1000 / Terrarum.appgc.fps
|
||||
if (Gdx.graphics.framesPerSecond > 0) {
|
||||
flickerFuncX += Gdx.graphics.framesPerSecond
|
||||
breathFuncX += Gdx.graphics.framesPerSecond
|
||||
pulsateFuncX += Gdx.graphics.framesPerSecond
|
||||
}
|
||||
|
||||
// flicker-related vars
|
||||
@@ -93,8 +95,8 @@ object BlockPropUtil {
|
||||
fun getDynamicLumFunc(baseLum: Int, type: Int): Int {
|
||||
return when (type) {
|
||||
1 -> getTorchFlicker(baseLum)
|
||||
2 -> Terrarum.ingame!!.world.globalLight // current global light
|
||||
3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2).toInt() // daylight at noon
|
||||
2 -> TerrarumGDX.ingame!!.world.globalLight // current global light
|
||||
3 -> WeatherMixer.getGlobalLightOfTime(WorldTime.DAY_LENGTH / 2).toRGB10() // daylight at noon
|
||||
4 -> getSlowBreath(baseLum)
|
||||
5 -> getPulsate(baseLum)
|
||||
else -> baseLum
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user