ソラマメブログ

  

Posted by at

2007年12月11日

LSLシンタックスハイライトのテスト

sabro さんのブログでLSLのシンタックスハイライトツールについての投稿があったので、
そこから色々たどって見ながら表示を変えてみました。

http://sabro.slmame.com/e30094.html
http://weblibrary.s224.xrea.com/weblog/web20/blog/dpsyntaxhighlig.html
http://code.google.com/p/syntaxhighlighter/


default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}

touch_start(integer total_number)
{
llSay(0, "Touched.");
}
}


改行を「 & # 1 0 ; 」に変換しないと行末に「 < B R > 」がついてしまうらしい。
「 & # 1 0 ; 」は実体参照と言うそうな。
見映えが良くなるのですが、変換は面倒である。
  


Posted by march at 19:02Comments(4)

2007年12月11日

libsecondlifeサンプル - チャットとIM送受信

チャンネルを指定したチャットや、相手のUUIDを指定したIMの送信ができます。
libsecondlifeのDeveloper Portal にある以下のページを参照してください。
http://www.libsecondlife.org/wiki/Say_something_inworld_%28chat%29
http://www.libsecondlife.org/wiki/Respond_to_inworld_chat
http://www.libsecondlife.org/wiki/Send_an_instant_message
http://www.libsecondlife.org/wiki/Respond_to_instant_messages

使い方によってはスパムになるので注意しましょう。


以下はサンプルコードです。
自分でチャットに発言した内容を自分で拾っています。
タイピングの開始/終了は出していません。
聞こえる範囲には、Whisper, Normal, Shoutの3つが選べます。
ChatType.Say は古い仕様で削除予定なので使用しないようにとの説明が上記のページにあります。
また、自分にIMを送信し受信しています。



#libsecondlifeのロード
import clr
clr.AddReferenceToFile("libsecondlife.dll")
import libsecondlife
import time

#ログイン情報の設定
firstName = 'abcd' #苗字
lastName = 'efgh' #名前
passWord = 'ijkl' #パスワード

#イベント待ち合わせ用クラスの定義
class EventTracker:
def __init__(self):
self.data=False
def Clear(self):
self.data=False
def Set(self):
self.data=True
def Wait(self):
while not self.data:
time.sleep(0.1)

#チャットイベント処理用ハンドラの定義
def chatHandler(message, hearRange, chatType, chatSourceType, agentName, uuid1, uuid2, locationVector):
print 'message =', message
print 'hearRange =', hearRange
print 'chatType =', chatType #StartTyping, Normal, StopTyping
print 'chatsourceType =', chatSourceType
print 'agentName =', agentName
print 'uuid1 =', uuid1 #SourceID?
print 'uuid2 =', uuid2 #OwnerID?
print 'locationVector =', locationVector

#IM受信イベント処理用のハンドラの定義
def instantMessageHandler(im, sim):
print 'sim=', sim.ToString()
attrList = [
'ToAgentID',
'FromAgentID',
'FromAgentName',
'ParentEstateID',
'RegionID',
'Position',
'Dialog',
'GroupIM',
'IMSessionID',
'Timestamp',
'Message',
'Offline',
'BinaryBucket'
]
for i in attrList:
print i, '=', eval('im.%s' % (i) )

#初期設定
event = EventTracker()
client = libsecondlife.SecondLife()
client.Self.OnChat += libsecondlife.AgentManager.ChatCallback(chatHandler)
client.Self.OnInstantMessage += libsecondlife.AgentManager.InstantMessageCallback(instantMessageHandler)

#接続
client.Network.Login(firstName, lastName, passWord, '', '')
time.sleep(10)

#実際の処理
#現在時刻をチャットで発言する
msg = 'now ' + time.strftime('%Y-%m-%d %H:%M:%S')
chatType = libsecondlife.ChatType.Normal #ChatType.Say is obsolete version and will likely be removed in the near future.
client.Self.Chat(msg, 0, chatType)
time.sleep(10)
#自分自身にIMを送信する
targetUuid = client.Self.AgentID
msg = 'now ' + time.strftime('%Y-%m-%d %H:%M:%S')
client.Self.InstantMessage(targetUuid, msg)
time.sleep(10)

#切断
client.Network.Logout()





AgentManager.cs には、グループIMを送信するための関数もあります。
AgentManager.cs を参照ください。
例:client.Self.InstantMessageGroup(groupUuid, msg)


チャットの内容から特定の単語を拾って、挨拶と簡単な受け答えができ、
詳しい話が聞きたいという人には、担当者を呼ぶのでお待ちくださいと言うような、
コールセンター風の使い方をしてもいいかもしれません。
(外見は普通のアバターですし)

  


Posted by march at 18:13Comments(0)libsecondlife

2007年12月11日

libsecondlifeサンプル - SIM統計情報の取得

SIMの統計情報(Ctrl+Shift+1で表示される情報)により、
SIMのFPS値やアバター数などを知ることが出来ます。
詳細は公式のSECOND LIFE HELPを参照してください。(ちょっと情報が古いようですが)
http://help.secondlife.com/jp/guides/stats.php
http://secondlife.com/app/help/guides/stats.php


現在いるSIMの統計情報を、client.Network.CurrentSim配下のStats構造体から取得できます。
取得のためのリクエストの発行は不要で、最新の情報のみが勝手に上記の構造体に格納されます。
(client.Settings.ENABLE_SIMSTATS はデフォルトでTrueになっています)

以下はサンプルコードです。

#libsecondlifeのロード
import clr
clr.AddReferenceToFile("libsecondlife.dll")
import libsecondlife
import time

#ログイン情報の設定
firstName = 'abcd' #苗字
lastName = 'efgh' #名前
passWord = 'ijkl' #パスワード


#初期設定、
client = libsecondlife.SecondLife()
#client.Settings.ENABLE_SIMSTATS = True

#接続
client.Network.Login(firstName, lastName, passWord, '', '')
time.sleep(10)

#実際の処理(SIM統計情報の取得)
sim = client.Network.CurrentSim
attrList = [
#debug-Simulator
'Dilation', #Time Dilation
'FPS', #Sim FPS
'PhysicsFPS', #Physics FPS
'AgentUpdates', #Agent Updates/Sec
'Agents', #Main Agents
'ChildAgents', #Child Agents
'Objects', #Objects
'ScriptedObjects', #Active Objects
'ActiveScripts', #Active Scripts
'LSLIPS', #Script Perf
'INPPS', #Packets In
'OUTPPS', #Packets Out
'PendingDownloads', #Pending Downloads
'PendingUploads', #Pending Uploads
'UnackedBytes', #Total Unacked Bytes
#debug-Simulator-Time(ms)
'FrameTime', #Total Frame Time
'NetTime', #Net Time
'PhysicsTime', #Sim Time (Physics)
'OtherTime', #Sim Time (Other)
'AgentTime', #Agent Time ##'Agent Time' not found. then LET 0.0
'ImageTime', #Images Time
'ScriptTime', #Script Time
]
for i in (attrList):
try:
val = eval('sim.Stats.%s' % (i) )
except AttributeError:
print i, 'AttributeError'
continue
print i, val

#切断
client.Network.Logout()





・libsecondlife0.2.0では、client.Network.CurrentSim の下に直接FPSなどの値が入っていました。
 0.3.0からその下にStatsという構造体で格納されるようになりました。(Simulator.cs参照)
・ScriptTimeには小さい値が、OtherTimeには大きな値が出力されています。
値の入れ方が逆なのかもしれません。


フォーラム(http://forums.opensecondlife.org/ )は落ちたままだし、
メーリングリストも動きがほとんどありません。
(サーバ移行でデータロスがあったとか投稿がありました)
復活を祈っています。
  


Posted by march at 11:32Comments(0)libsecondlife