diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..16398870 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,59 @@ +[*] +cpp_indent_braces=false +cpp_indent_multi_line_relative_to=innermost_parenthesis +cpp_indent_within_parentheses=indent +cpp_indent_preserve_within_parentheses=false +cpp_indent_case_labels=false +cpp_indent_case_contents=true +cpp_indent_case_contents_when_block=false +cpp_indent_lambda_braces_when_parameter=true +cpp_indent_goto_labels=one_left +cpp_indent_preprocessor=leftmost_column +cpp_indent_access_specifiers=false +cpp_indent_namespace_contents=true +cpp_indent_preserve_comments=false +cpp_new_line_before_open_brace_namespace=ignore +cpp_new_line_before_open_brace_type=ignore +cpp_new_line_before_open_brace_function=ignore +cpp_new_line_before_open_brace_block=ignore +cpp_new_line_before_open_brace_lambda=ignore +cpp_new_line_scope_braces_on_separate_lines=false +cpp_new_line_close_brace_same_line_empty_type=false +cpp_new_line_close_brace_same_line_empty_function=false +cpp_new_line_before_catch=true +cpp_new_line_before_else=true +cpp_new_line_before_while_in_do_while=false +cpp_space_before_function_open_parenthesis=remove +cpp_space_within_parameter_list_parentheses=false +cpp_space_between_empty_parameter_list_parentheses=false +cpp_space_after_keywords_in_control_flow_statements=true +cpp_space_within_control_flow_statement_parentheses=false +cpp_space_before_lambda_open_parenthesis=false +cpp_space_within_cast_parentheses=false +cpp_space_after_cast_close_parenthesis=false +cpp_space_within_expression_parentheses=false +cpp_space_before_block_open_brace=true +cpp_space_between_empty_braces=false +cpp_space_before_initializer_list_open_brace=false +cpp_space_within_initializer_list_braces=true +cpp_space_preserve_in_initializer_list=true +cpp_space_before_open_square_bracket=false +cpp_space_within_square_brackets=false +cpp_space_before_empty_square_brackets=false +cpp_space_between_empty_square_brackets=false +cpp_space_group_square_brackets=true +cpp_space_within_lambda_brackets=false +cpp_space_between_empty_lambda_brackets=false +cpp_space_before_comma=false +cpp_space_after_comma=true +cpp_space_remove_around_member_operators=true +cpp_space_before_inheritance_colon=true +cpp_space_before_constructor_colon=true +cpp_space_remove_before_semicolon=true +cpp_space_after_semicolon=false +cpp_space_remove_around_unary_operator=true +cpp_space_around_binary_operator=insert +cpp_space_around_assignment_operator=insert +cpp_space_pointer_reference_alignment=left +cpp_space_around_ternary_operator=insert +cpp_wrap_preserve_blocks=one_liners diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..3d244213 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,54 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Unity Editor", + "type": "unity", + "path": "/Users/yadosan/Dropbox/My Mac (Yutas-MacBook-Pro.local)/Documents/Unity/LG/Library/EditorInstance.json", + "request": "launch" + }, + { + "name": "Windows Player", + "type": "unity", + "request": "launch" + }, + { + "name": "OSX Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Linux Player", + "type": "unity", + "request": "launch" + }, + { + "name": "iOS Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Android Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Xbox One Player", + "type": "unity", + "request": "launch" + }, + { + "name": "PS4 Player", + "type": "unity", + "request": "launch" + }, + { + "name": "SwitchPlayer", + "type": "unity", + "request": "launch" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..0083bb46 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.exclude": { + "**/*.meta": true + } +} \ No newline at end of file diff --git a/Assets/.DS_Store b/Assets/.DS_Store index ee1cf595..8e6ee35a 100644 Binary files a/Assets/.DS_Store and b/Assets/.DS_Store differ diff --git a/Assets/DotManage.cs b/Assets/DotManage.cs index dbfed75c..13b92705 100644 --- a/Assets/DotManage.cs +++ b/Assets/DotManage.cs @@ -4,20 +4,20 @@ public class DotManage : MonoBehaviour { - - public int x, y, z; - public int state = 0; //num of own - public int neighbor = 0; //num of around - - public bool isAlive = false; - - public void dotGenerate() + + public int x, y, z; + public int state = 0; //num of own + public int neighbor = 0; //num of around + + public bool isAlive = false; + + public void dotGenerate() { - transform.GetChild(0).gameObject.SetActive(true); + transform.GetChild(0).gameObject.SetActive(true); isAlive = true; } - public void dotDestroy() + public void dotDestroy() { transform.GetChild(0).gameObject.SetActive(false); isAlive = false; diff --git a/Assets/DotManageSparse.cs b/Assets/DotManageSparse.cs index 26e77f0b..a11a6ec8 100644 --- a/Assets/DotManageSparse.cs +++ b/Assets/DotManageSparse.cs @@ -1,21 +1,9 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class DotManageSparse : PoolObj -{ - //public int x, y, z; - //public int state = 0; //num of own - //public int neighbor = 0; //num of around - - //public bool isAlive; - - //// Update is called once per frame - //void Update() - //{ - // DotManageSparse.Pool(this); - //} +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +public class DotManageSparse : PoolObj +{ public override void Init() { gameObject.SetActive(true); @@ -24,6 +12,6 @@ public override void Init() public override void Sleep() { gameObject.SetActive(false); - } - -} + } + +} diff --git a/Assets/GameManageSparse.cs b/Assets/GameManageSparse.cs index 0fe32502..ea281b61 100644 --- a/Assets/GameManageSparse.cs +++ b/Assets/GameManageSparse.cs @@ -1,108 +1,114 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.SceneManagement; - -using System.IO; -using System.Text; -using SimpleFileBrowser; -using System.Linq; +using System.Globalization; +using System.Diagnostics; +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.SceneManagement; + +using System.IO; +using System.Text; +using SimpleFileBrowser; +using System.Linq; using System.Threading.Tasks; -public class GameManageSparse : MonoBehaviour -{ - [SerializeField] int n = 1024; //infinite universe +public class GameManageSparse : MonoBehaviour +{ + [SerializeField] int n = 2048; //infinite universe [SerializeField] int r1 = 4, r2 = 4, r3 = 0, r4 = 0; //rules - [SerializeField] int range = 6; //apprear range + [SerializeField] int range; //apprear range int pre_x, pre_y, pre_z; Vector3 head_location; //change pos to location - [SerializeField] GameObject head_pref; //head prefab flag_ - [SerializeField] GameObject dot_pref; //dot prefab flag_ - - List displaying_dots_list = new List(); //the list of dots that's displaying now - + [SerializeField] GameObject head_pref; //head prefab flag_ + [SerializeField] GameObject dot_pref; //dot prefab flag_ + + // the list of dots that's displaying now + // I need this when I delete all cells in a scene + List displaying_dots_list = new List(); + Dictionary, int> current_cell_list = new Dictionary, int>(); - Dictionary, int> cell_list_for_judge = new Dictionary, int>(); - - // if cell_location_matrix[x,y,z] == 1, the cell near by the player will be appeared - Sparse3DArray cell_location_matrix = new Sparse3DArray(); - - float dotInterval = 1; - public float bpm; - float bar, beat; - //timeRecent is the time to refresh model with chords, timeRecent2 is the time to refresh model with sequential. - float timeRecent = 1, timeRecent2 = 0; - + Dictionary, int> cell_list_for_judge = new Dictionary, int>(); + + // if cell_location_matrix[x,y,z] == 1, the cell near by the player will be appeared + Sparse3DArray cell_location_matrix = new Sparse3DArray(); + Sparse3DArray pre_cell_location_matrix; + + float dotInterval = 1; + public float bpm; + float bar, beat; + //timeRecent is the time to refresh model with chords, timeRecent2 is the time to refresh model with sequential. + float timeRecent = 1, timeRecent2 = 0; + bool isRun = true, isPeriodic = true, isSequential = false; // Awake is called before Start void Awake() { DotManageSparse.SetOriginal(dot_pref); //flag_ - } - - // Start is called before the first frame update - void Start() + } + + // Start is called before the first frame update + void Start() { //setting head_pref position flag_ head_pref.transform.position = new Vector3(((-n / 2.0f) + ((n / 2.0f) - 1)) / 2.0f, ((-n / 2.0f) + ((n / 2.0f) - 1)) / 2.0f, ((-n / 2.0f) + ((n / 2.0f) - 1)) / 2.0f); - ////Random Debug - //for (int i = n / 2 - 4; i < n / 2 + 4; i++) - //{ - // for (int j = n / 2 - 4; j < n / 2 + 4; j++) - // { - // for (int k = n / 2 - 4; k < n / 2 + 4; k++) - // { - // if (UnityEngine.Random.Range(0, 5) == 0) - // { - // cell_location_matrix[i, j, k] = 1; - // var key1 = new Tuple(i, j, k); - // current_cell_list.Add(key1, 0); - // } - // } - // } - //} - - ////Blinker Debug - //cell_location_matrix[n / 2, n / 2, n / 2] = 1; - //var key1 = new Tuple(n / 2, n / 2, n / 2); - //current_cell_list.Add(key1, 0); - - //cell_location_matrix[n / 2 + 1, n / 2, n / 2] = 1; - //var key2 = new Tuple(n / 2 + 1, n / 2, n / 2); - //current_cell_list.Add(key2, 0); - - //cell_location_matrix[n / 2, n / 2 + 1, n / 2 + 1] = 1; - //var key3 = new Tuple(n / 2, n / 2 + 1, n / 2 + 1); - //current_cell_list.Add(key3, 0); - - //cell_location_matrix[n / 2 + 1, n / 2 + 1, n / 2 + 1] = 1; - //var key4 = new Tuple(n / 2 + 1, n / 2 + 1, n / 2 + 1); - //current_cell_list.Add(key4, 0); - - cell_location_matrix[n / 2, n / 2, n / 2] = 1; - var key1 = new Tuple(n / 2, n / 2, n / 2); - current_cell_list.Add(key1, 0); - - cell_location_matrix[n / 2, n / 2, n / 2 + 1] = 1; - var key2 = new Tuple(n / 2, n / 2, n / 2 + 1); - current_cell_list.Add(key2, 0); - - cell_location_matrix[n / 2, n / 2 + 1, n / 2] = 1; - var key3 = new Tuple(n / 2, n / 2 + 1, n / 2); - current_cell_list.Add(key3, 0); - - cell_location_matrix[n / 2, n / 2 + 1, n / 2 + 1] = 1; - var key4 = new Tuple(n / 2, n / 2 + 1, n / 2 + 1); - current_cell_list.Add(key4, 0); - - } - - void Update() + //Random Debug + for (int i = n / 2 - 4; i < n / 2 + 4; i++) + { + for (int j = n / 2 - 4; j < n / 2 + 4; j++) + { + for (int k = n / 2 - 4; k < n / 2 + 4; k++) + { + if (UnityEngine.Random.Range(0, 5) == 0) + { + cell_location_matrix[i, j, k] = 1; + var key1 = new Tuple(i, j, k); + current_cell_list.Add(key1, 0); + } + } + } + } + + // //Blinker Debug + // cell_location_matrix[n / 2, n / 2, n / 2] = 1; + // var key1 = new Tuple(n / 2, n / 2, n / 2); + // current_cell_list.Add(key1, 0); + + // cell_location_matrix[n / 2 + 1, n / 2, n / 2] = 1; + // var key2 = new Tuple(n / 2 + 1, n / 2, n / 2); + // current_cell_list.Add(key2, 0); + + // cell_location_matrix[n / 2, n / 2 + 1, n / 2 + 1] = 1; + // var key3 = new Tuple(n / 2, n / 2 + 1, n / 2 + 1); + // current_cell_list.Add(key3, 0); + + // cell_location_matrix[n / 2 + 1, n / 2 + 1, n / 2 + 1] = 1; + // var key4 = new Tuple(n / 2 + 1, n / 2 + 1, n / 2 + 1); + // current_cell_list.Add(key4, 0); + + // //Rocket + // cell_location_matrix[n / 2, n / 2, n / 2] = 1; + // var key1 = new Tuple(n / 2, n / 2, n / 2); + // current_cell_list.Add(key1, 0); + + // cell_location_matrix[n / 2, n / 2, n / 2 + 1] = 1; + // var key2 = new Tuple(n / 2, n / 2, n / 2 + 1); + // current_cell_list.Add(key2, 0); + + // cell_location_matrix[n / 2, n / 2 + 1, n / 2] = 1; + // var key3 = new Tuple(n / 2, n / 2 + 1, n / 2); + // current_cell_list.Add(key3, 0); + + // cell_location_matrix[n / 2, n / 2 + 1, n / 2 + 1] = 1; + // var key4 = new Tuple(n / 2, n / 2 + 1, n / 2 + 1); + // current_cell_list.Add(key4, 0); + + } + + void Update() { //Moving the head head_location = head_pref.transform.position; @@ -118,26 +124,29 @@ void Update() { timeRecent2 += Time.deltaTime; + //Store previous location of the head. + pre_x = (int)head_location.x; + pre_y = (int)head_location.y; + pre_z = (int)head_location.z; + //View update //Updates the view when the player's position changes in integer increments - if (pre_x != (int)head_location.x || pre_y != (int)head_location.y || pre_z != (int)head_location.z || timeRecent == 0) - { - //Store previous location of the head. - pre_x = (int)head_location.x; - pre_y = (int)head_location.y; - pre_z = (int)head_location.z; - - UpdateDotView(); - } - - if (timeRecent == 0) { timeRecent++; Judge(); - + //UpdateDotView(); } + // I dun know why this process causes a lag :( + // if (pre_x != (int)head_location.x || pre_y != (int)head_location.y || pre_z != (int)head_location.z) + // { + // UpdateDotView(); + // } + + + UpdateDotView(); + if (timeRecent2 >= (bar / 4.0) && !isSequential) { timeRecent = 0; @@ -147,41 +156,49 @@ void Update() } - } - - public void UpdateDotView() + } + + public void UpdateDotView() { + //clear all cells displayed on scene foreach (DotManageSparse e in displaying_dots_list) { DotManageSparse.Pool(e); } displaying_dots_list.Clear(); + float count = 0f; + for (int i = (int)head_location.x + (n / 2) - range; i < (int)head_location.x + (n / 2) + range; i++) { for (int j = (int)head_location.y + (n / 2) - range; j < (int)head_location.y + (n / 2) + range; j++) { for (int k = (int)head_location.z + (n / 2) - range; k < (int)head_location.z + (n / 2) + range; k++) { + count++; DotManageSparse displaying_dot = DotManageSparse.Create(); - displaying_dots_list.Add(displaying_dot); displaying_dot.transform.position = new Vector3(dotInterval * (-n / 2.0f + i), dotInterval * (-n / 2.0f + j), dotInterval * (-n / 2.0f + k)); + displaying_dot.transform.GetChild(0).gameObject.GetComponent().material.color = Color.HSVToRGB(count / (8f * 8f * 8f), 1f, 1f); + displaying_dots_list.Add(displaying_dot); if (cell_location_matrix[i, j, k] == 1) { + //appear alive displaying_dot.transform.GetChild(0).gameObject.SetActive(true); } else { + //appear dead displaying_dot.transform.GetChild(0).gameObject.SetActive(false); } } } - } - - } - + } + + } + public async void Judge() - { + { + //do this statement asynchronously. await Task.Run(() => { //add cells to alives and deads @@ -243,9 +260,11 @@ await Task.Run(() => } } + //clear cells in cell_location_matrix and current_cell_list. cell_location_matrix.dataClear(); current_cell_list.Clear(); + //add current cell's location **this takes a minute (means heavy process)** foreach (var e in cell_list_for_judge) { if (e.Value <= r2 && e.Value >= r1) @@ -256,10 +275,12 @@ await Task.Run(() => } } + UnityEngine.Debug.Log(cell_list_for_judge.Count()); + //clear cells in cell_list_for_judge cell_list_for_judge.Clear(); - }); - - } - -} + }); + + } + +} diff --git a/Assets/Materials/Dead.mat b/Assets/Materials/Dead.mat index 1d7494da..e7f69772 100644 --- a/Assets/Materials/Dead.mat +++ b/Assets/Materials/Dead.mat @@ -74,6 +74,6 @@ Material: - _UVSec: 0 - _ZWrite: 0 m_Colors: - - _Color: {r: 0.26415092, g: 0.23798503, b: 0.23798503, a: 0.21176471} + - _Color: {r: 0, g: 0, b: 0, a: 0.21176471} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Scenes/Sparse.unity b/Assets/Scenes/Sparse.unity index 00e6a01d..3ad8a5f7 100644 --- a/Assets/Scenes/Sparse.unity +++ b/Assets/Scenes/Sparse.unity @@ -449,7 +449,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1217d0940cd414e7bafa0ae9b974ead4, type: 3} m_Name: m_EditorClassIdentifier: - speed: 0.1 + speed: 0.2 --- !u!81 &1975725066 AudioListener: m_ObjectHideFlags: 0 diff --git a/Assets/dotPool.cs b/Assets/dotPool.cs deleted file mode 100644 index f367c6c5..00000000 --- a/Assets/dotPool.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class dotPool : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/dotPool.cs.meta b/Assets/dotPool.cs.meta deleted file mode 100644 index f08db6e8..00000000 --- a/Assets/dotPool.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 53e41499f3dfb439eb617af9c9910d00 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/_image/demo.mp4 b/_image/demo.mp4 deleted file mode 100644 index 22476894..00000000 Binary files a/_image/demo.mp4 and /dev/null differ