ソラマメブログ

2008年07月02日

グラマブル噴水 リファクタリングしてみようかな(その3)

できた...
-----
バグっていたと書いていたが メッセージが届いていなかっただけで メッセージが届くようノートを修正するだけで起動した w
-----
というわけで リストあげておきます
-----
まず本体から
//
// File: programmable_fountain2.lsl
// Date Author number of nodes
// 2008/7/2 walkinglint 170
// 2008/7/1 walkinglint 171
//
string start_str = "start";
string stop_str = "stop";
string start_color_str = "start_color";
string end_color_str = "end_color";
integer min_link_num = 1;
integer max_link_num = 6; // customize here to add nozzle
integer size_of_record = 5;
// duration,source(LINK_SET -1/LINK_ALL_OTHERS -2/LINK_ALL_CHILDREN -3),operation,hight,target
list seq;
list seq0 = [];
list seq1 = [];
list seq2 = [];
list seq3 = [];
list seq4 = [];
list seq5 = [];
list seq6 = [];
list seq7 = [];
list seq8 = [];
list seq_list = [];
vector default_start_color = <0.50, 0.50, 1.00>;
vector default_end_color = <1.00, 1.00, 1.00>;
list default_seq;
integer num_of_seq;
list cur_seq;
integer cur_seq_num;
float cur_duration;
integer cur_src_link;
string cur_operation;
integer cur_hight;
integer cur_target_link;
integer programmable_fountain_channel = 22102;
integer handle;
string notecard_name;
integer read_line;
key query_id;
integer cur_note_num;
integer max_note_num;
get_record() {
cur_src_link = llList2Integer(cur_seq, 1);
cur_operation = llList2String (cur_seq, 2);
cur_hight = llList2Integer(cur_seq, 3);
cur_target_link = llList2Integer(cur_seq, 4);
}
float update_cur_seq_and_get_duration() {
cur_seq = llList2List(seq, cur_seq_num * size_of_record, (cur_seq_num + 1) * size_of_record - 1);
if (++cur_seq_num > num_of_seq) {
cur_seq_num = 0;
}
return llList2Float(cur_seq, 0);
}
stop_fountain() {
integer i;
for (i = min_link_num; i <= max_link_num; i++) {
llMessageLinked(i, 0, stop_str, NULL_KEY);
}
}
integer vector2int(vector v) {
return (integer)(v.x * 100000) + (integer)(v.y * 1000) + (integer) v.z * 10;
}
set_default_colors() {
llMessageLinked(LINK_SET, vector2int(default_start_color), start_color_str, NULL_KEY);
llMessageLinked(LINK_SET, vector2int(default_end_color), end_color_str, NULL_KEY);
}
set_seq_and_start() {
cur_note_num = 0;
max_note_num = llGetInventoryNumber(INVENTORY_NOTECARD);
notecard_name = llGetInventoryName(INVENTORY_NOTECARD, cur_note_num);
read_line = 0;
query_id = llGetNotecardLine(notecard_name, read_line);
}
default {
state_entry() {
set_seq_and_start();
stop_fountain();
llParticleSystem([]);
set_seq_and_start();
}
on_rez(integer param) {
llResetScript();
}
touch_start(integer total_number) {
llDialog(llDetectedKey(0), "Select pattern", seq_list, 123);
handle = llListen(123, "", "", "");
}
listen(integer channel, string name, key id, string message) {
integer idx = llListFindList(seq_list, [message]);
set_default_colors();
if (idx == 0) {
seq = seq0;
} else if (idx == 1) {
seq = seq1;
} else if (idx == 2) {
seq = seq2;
} else if (idx == 3) {
seq = seq3;
} else if (idx == 4) {
seq = seq4;
} else if (idx == 5) {
seq = seq5;
} else if (idx == 6) {
seq = seq6;
} else if (idx == 7) {
seq = seq7;
} else if (idx == 8) {
seq = seq8;
} else {
// do not comes here
}
stop_fountain();
num_of_seq = llGetListLength(seq) / size_of_record;
cur_seq_num = 0;
llSetTimerEvent(1.0);
llListenRemove(handle);
}
timer() {
integer max_count = 0;
while ((cur_duration = update_cur_seq_and_get_duration()) == 0.0) {
get_record();
if (cur_target_link == 0) {
llMessageLinked(cur_src_link, cur_hight, cur_operation, NULL_KEY);
} else {
llMessageLinked(cur_src_link, cur_hight, cur_operation, llGetLinkKey(cur_target_link));
}
if (++max_count > num_of_seq) {
llSetTimerEvent(0.0);
return ;
}
}
get_record();
if (cur_target_link == 0) {
llMessageLinked(cur_src_link, cur_hight, cur_operation, NULL_KEY);
} else {
llMessageLinked(cur_src_link, cur_hight, cur_operation, llGetLinkKey(cur_target_link));
}
llSetTimerEvent(cur_duration);
}
dataserver(key queryid, string data) {
if (queryid == query_id) {
if (data != EOF) {
// process data
integer l = llSubStringIndex(data, "//");
if (l == 0) {
data = "";
} else if (l != -1) {
data = llGetSubString(data, 0, l - 1);
}
if (llStringLength(data) != 0) {
if (cur_note_num == 0) {
seq0 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 1) {
seq1 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 2) {
seq2 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 3) {
seq3 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 4) {
seq4 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 5) {
seq5 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 6) {
seq6 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 7) {
seq7 += llParseString2List(data, [",", " "], []);
} else if (cur_note_num == 8) {
seq8 += llParseString2List(data, [",", " "], []);
}
}
read_line++;
query_id = llGetNotecardLine(notecard_name, read_line);
} else {
llOwnerSay("Loading " + notecard_name + " complete.");
seq_list += notecard_name;
cur_note_num++;
if (cur_note_num < max_note_num) {
notecard_name = llGetInventoryName(INVENTORY_NOTECARD, cur_note_num);
read_line = 0;
query_id = llGetNotecardLine(notecard_name, read_line);
} else {
default_seq = seq0;
seq = default_seq;
num_of_seq = llGetListLength(seq) / size_of_record;
cur_seq_num = 0;
llSetTimerEvent(1.0);
}
}
}
}
}
次にノズル
//
// File: nozzle2.lsl
// Date Author number of nodes
// 2008/7/2 walkinglint 52
// 2008/7/2 walkinglint 45 (nozzle->nozzle2)
// 2008/7/1 walkinglint 36
//
string start_str = "start";
string stop_str = "stop";
string start_color_str = "start_color";
string end_color_str = "end_color";
string flag_str = "flag";
vector default_start_color = <0.50,0.50,1.00>;
vector default_end_color = <1.00,1.00,1.00>;
integer default_flag = 259;
string default_texture = "bbf5a4bf-4971-4db7-905a-0235b2757dec";
vector start_color = default_start_color;
vector end_color = default_end_color;
integer flag = default_flag;
string texture = default_texture;
ParticleStart(integer flag, float hight, key target) {
llParticleSystem([
PSYS_PART_FLAGS, 259 | PSYS_PART_TARGET_POS_MASK,
PSYS_SRC_PATTERN, 2,
PSYS_PART_START_ALPHA, 1.00,
PSYS_PART_END_ALPHA, 0.10,
PSYS_PART_START_COLOR, start_color,
PSYS_PART_END_COLOR, end_color,
PSYS_PART_START_SCALE, <0.2,0.2,0.00>,
PSYS_PART_END_SCALE, <0.7,0.7,0.00>,
PSYS_PART_MAX_AGE, 6.0,
PSYS_SRC_TARGET_KEY, target,
PSYS_SRC_MAX_AGE, 0.00,
PSYS_SRC_ACCEL, <0.00, 0.00, hight>,
PSYS_SRC_ANGLE_BEGIN, 0.00,
PSYS_SRC_ANGLE_END, 0.70,
PSYS_SRC_BURST_PART_COUNT, 10,
PSYS_SRC_BURST_RADIUS, 0.01,
PSYS_SRC_BURST_RATE, 0.05,
PSYS_SRC_BURST_SPEED_MIN, 0.00,
PSYS_SRC_BURST_SPEED_MAX, 0.40,
PSYS_SRC_OMEGA, <0.00,0.00,0.00>,
PSYS_SRC_TEXTURE, texture
]);
}
ParticleEnd() {
llParticleSystem([]);
}
vector int2vector(integer i) {
vector v;
v.x = (float)(i / 10000) / 10.0;
integer tmp = i % 10000;
v.y = (float)(tmp / 100) / 10.0;
v.z = (float)(tmp % 100) / 10.0;
return v;
}
default {
link_message(integer sender_num, integer num, string str, key id) {
if (str == start_str) {
if (id == NULL_KEY) {
ParticleStart(flag, (float)num, id);
} else {
ParticleStart(flag | PSYS_PART_TARGET_POS_MASK, (float)num, id);
}
} else if (str == stop_str) {
ParticleEnd();
} else if (str == start_color_str) {
start_color = int2vector(num);
} else if (str == end_color_str) {
end_color = int2vector(num);
} else if (str == flag_str) {
flag = num;
} else {
texture = str;
}
}
}
最後にノートカードにいれるデータのサンプル(基本的に内部に list で持たせていたものをノートカードの方にもっていっただけ)
// duration,source(LINK_SET -1/LINK_ALL_OTHERS -2/LINK_ALL_CHILDREN -3),operation,hight,target
0.0, -1, a66561d5-8e15-a591-a00b-2e818aa42ea3, 0, 0
0.0, -1, flag, 291, 0 // 259 | PSYS_PART_FOLLOW_VELOCITY_MASK(0x020)
0.0, 1, start, 4, 0
0.0, -2, start, 1, 0
このノートカードの名前は 0
-----
ノートカードの名前をそのままシーケンスのパターンの名前として用い クリックした場合に表示されるダイアログのボタンの名前にしています ^^

同じカテゴリー(walking のスクリプティング講座)の記事
 プロフィール写真の表示に問題 (2009-11-30 20:55)
 ミニ太陽系 (2009-03-21 06:03)
 関数から文字列を返したら何か問題になる? (2009-03-18 18:02)
 llListFindList って型って関係ないんだったっけ (2009-03-18 14:02)
 夏時間(PDT)の実験 (2009-03-08 22:04)
 15パズルの作り方(その3) (2009-03-08 06:03)
上の画像に書かれている文字を入力して下さい
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。