-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecbad78
commit 7f50d47
Showing
21 changed files
with
891 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: timelessCellularAutomata.crbm.Start | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** Ben F Rayfield offers HumanAiCore opensource GNU LGPL */ | ||
package humanaicore.common; | ||
import java.util.concurrent.ForkJoinPool; | ||
|
||
public class Parallel{ | ||
private Parallel(){} | ||
|
||
public static final ForkJoinPool cpus; | ||
static{ | ||
int howManyCpus = Runtime.getRuntime().availableProcessors(); | ||
/*ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory(){ | ||
public ForkJoinWorkerThread newThread(ForkJoinPool pool){ | ||
ForkJoinWorkerThread t = new ForkJoinWorkerThread(pool){ | ||
}; | ||
} | ||
}; | ||
UncaughtExceptionHandler handler = new UncaughtExceptionHandler(){ | ||
public void uncaughtException(Thread t, Throwable e){ | ||
throw new Err(e); | ||
} | ||
}; | ||
boolean asyncMode = false; | ||
cpus = new ForkJoinPool(howManyCpus, factory, handler, asyncMode); | ||
*/ | ||
cpus = new ForkJoinPool(howManyCpus); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package humanaicore.common; | ||
//import static log.Lg.*; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
/** Synchronized Var */ | ||
public class SVar<T> implements Supplier<T>, Consumer<T>{ | ||
|
||
protected T value; | ||
|
||
protected final Set<Consumer<SVar<T>>> listeners = new HashSet(); | ||
|
||
public SVar(T firstValue){ | ||
value = firstValue; | ||
//lgErr("Constructor SVar.value="+this.value); | ||
} | ||
|
||
public synchronized void startListening(Consumer<SVar<T>> listener){ | ||
listeners.add(listener); | ||
} | ||
|
||
public synchronized void stopListening(Consumer<SVar<T>> listener){ | ||
listeners.remove(listener); | ||
} | ||
|
||
public synchronized void stopAllListeners(){ | ||
listeners.clear(); | ||
} | ||
|
||
/** Unsynchronized for speed, allowed cuz a pointer wont be split by thread-error */ | ||
public T get(){ | ||
//lgErr("Get SVar.value="+this.value); | ||
return value; | ||
} | ||
|
||
public synchronized void accept(T value){ | ||
this.value = value; | ||
//lgErr("Set SVar.value="+this.value); | ||
for(Consumer<SVar<T>> listener : listeners){ | ||
listener.accept(this); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** Ben F Rayfield offers HumanAiCore opensource GNU LGPL */ | ||
package humanaicore.common; | ||
|
||
import java.text.DecimalFormat; | ||
|
||
public class Time{ | ||
private Time(){} | ||
|
||
public static final long startMillis; | ||
|
||
public static final long startNano; | ||
|
||
public static final int secondsPerDay = 24*60*60; | ||
|
||
protected static final DecimalFormat secondsFormat = new DecimalFormat("0000000000.0000000"); | ||
|
||
protected static final DecimalFormat stardateFormat = new DecimalFormat("00000.000000000000"); | ||
|
||
static{ | ||
startMillis = System.currentTimeMillis(); | ||
startNano = System.nanoTime(); | ||
} | ||
|
||
/** Seconds since year 1970 | ||
with relative nanosecond precision (System.nanoTime) | ||
and absolute few milliseconds precision (System.currentTimeMillis). | ||
<br><br> | ||
Practically, at least in normal computers in year 2011, this has about microsecond precision | ||
because you can only run it a few million times per second. | ||
TODO test it again on newer computers. | ||
*/ | ||
public static double time(){ | ||
//TODO optimize by caching the 2 start numbers into 1 double */ | ||
long nanoDiff = System.nanoTime()-startNano; | ||
return .001*startMillis + 1e-9*nanoDiff; | ||
} | ||
|
||
public static String timeStr(){ | ||
return timeStr(time()); | ||
} | ||
|
||
public static String timeStr(double time){ | ||
return secondsFormat.format(time); | ||
} | ||
|
||
public static String stardateStr(){ | ||
return stardateStr(time()); | ||
} | ||
|
||
/** number of 24 hour blocks since year 1970 */ | ||
public static String stardateStr(double time){ | ||
return stardateFormat.format(time/secondsPerDay); | ||
} | ||
|
||
/** Uses Thread.sleep(milliseconds,nanoseconds) for extra accuracy, | ||
but don't count on Java running threads often enough to use the extra accuracy on all computers. | ||
*/ | ||
public static void sleep(double seconds) throws InterruptedException{ | ||
if(seconds <= 0) return; | ||
double millis = seconds*1e3; | ||
long millisL = (long)millis; | ||
millis -= millisL; | ||
double nanos = millis*1e6; | ||
int nanosI = (int)Math.round(nanos); | ||
Thread.sleep(millisL, nanosI); | ||
} | ||
|
||
public static void sleepNoThrow(double seconds){ | ||
try{ | ||
sleep(seconds); | ||
}catch(InterruptedException e){} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package log; | ||
|
||
|
||
/** Use the following line at the top of each source code file: | ||
import static commonfuncs.CommonFuncs.*; | ||
<br><br> | ||
This is more like functional programming than object oriented. | ||
*/ | ||
public class Lg{ | ||
private Lg(){} | ||
|
||
public static void lgNobr(String s){ | ||
System.out.print(s); | ||
} | ||
|
||
public static void lg(Object o){ | ||
lg(o.toString()); //could have ""+o but thats slower | ||
} | ||
|
||
public static void lg(String line){ | ||
System.out.println(line); | ||
} | ||
|
||
public static void lgErr(Object o){ | ||
lgErr(o.toString()); //could have ""+o but thats slower | ||
} | ||
|
||
public static void lgErr(String line){ | ||
System.err.println(line); | ||
} | ||
|
||
public static void lgToUser(Object o){ | ||
lgToUser(o.toString()); //could have ""+o but thats slower | ||
} | ||
|
||
public static void lgToUser(String line){ | ||
System.err.println(line); | ||
} | ||
|
||
/** Since JSelfModify doesnt have a User system yet, just room for expansion, | ||
this function uses JSelfModify.rootUser as is normally done. | ||
WARNING: This kind of thing will need to be redesigned securely when we start having usernames. | ||
* | ||
public static Object jsmGet(String path){ | ||
try{ | ||
return JSelfModify.root.get(JSelfModify.rootUser, path); | ||
}catch(Exception e){ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
/** See WARNING in jsmGet * | ||
public static void jsmPut(String path, Object value){ | ||
try{ | ||
JSelfModify.root.put(JSelfModify.rootUser, path, value); | ||
}catch(Exception e){ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
/** See WARNING in jsmGet * | ||
public static boolean jsmExist(String path){ | ||
try{ | ||
return JSelfModify.root.exist(JSelfModify.rootUser, path); | ||
}catch(Exception e){ | ||
throw new RuntimeException(e); | ||
} | ||
}*/ | ||
|
||
/** returns a debug string summarizing a pointer into an acyc as an object * | ||
public static String str(int pointerIntoAcyc){ | ||
return XobUtil.describeGlobal(pointerIntoAcyc); | ||
}*/ | ||
|
||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ssCellularAutomata/BoltzCellAutomata.java → ...larAutomata/cboltz/BoltzCellAutomata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
timelessCellularAutomata/Start.java → ...imelessCellularAutomata/cboltz/Start.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
timelessCellularAutomata/ui/GamePanel.java → ...CellularAutomata/cboltz/ui/GamePanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.