[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10916] trunk/blender/source/blender/ blenkernel: === Verse ===

Nathan Letwory jesterking at letwory.net
Mon Jun 11 12:42:38 CEST 2007


Revision: 10916
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=10916
Author:   jesterking
Date:     2007-06-11 12:42:38 +0200 (Mon, 11 Jun 2007)

Log Message:
-----------
=== Verse ===

* add preliminary verse method support to Blender. This gets really interesting whenever I get Verse Chat completed.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_verse.h
    trunk/blender/source/blender/blenkernel/intern/verse_node.c
    trunk/blender/source/blender/blenkernel/intern/verse_object_node.c
    trunk/blender/source/blender/blenkernel/intern/verse_session.c

Added Paths:
-----------
    trunk/blender/source/blender/blenkernel/intern/verse_method.c

Modified: trunk/blender/source/blender/blenkernel/BKE_verse.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_verse.h	2007-06-11 08:42:54 UTC (rev 10915)
+++ trunk/blender/source/blender/blenkernel/BKE_verse.h	2007-06-11 10:42:38 UTC (rev 10916)
@@ -335,7 +335,31 @@
 	void (*post_taggroup_create)(struct VTagGroup *vtaggroup);
 } VTagGroup;
 
+ /*
+ * Verse Method Group
+ */
+typedef struct VMethodGroup
+{
+	struct VMethodGroup *next, *prev;
+	uint16 group_id;
+	char name[16];
+	struct ListBase methods;
+} VMethodGroup;
+
 /*
+ * Verse Method
+ */
+typedef struct VMethod
+{
+	struct VMethod *next, *prev;
+	uint16 id;
+	char name[500];
+	uint8 param_count;
+	VNOParamType *param_type;
+	char **param_name;
+} VMethod;
+
+/*
  * Verse Node
  */
 typedef struct VNode {
@@ -349,6 +373,7 @@
 	/* blender internals */
 	char flag;			/* flags: NODE_SENT, NODE_RECEIVED, NODE_DELTED, NODE_OBSOLETE */
 	struct DynamicList taggroups;	/* dynamic list with access array of taggroups */
+	struct ListBase methodgroups;	/* method groups */
 	struct ListBase queue;		/* list of taggroups waiting for receiving from verse server */
 	void *data;			/* generic pointer at some data (VObjectData, VGeomData, ...) */
 	int counter;			/* counter of verse link pointing at this vnode (vlink->target) */
@@ -356,6 +381,10 @@
 	void (*post_node_create)(struct VNode *vnode);	
 	void (*post_node_destroy)(struct VNode *vnode);
 	void (*post_node_name_set)(struct VNode *vnode);
+#ifdef VERSECHAT
+	/* verse chat */
+	int chat_flag;			/* CHAT_LOGGED, CHAT_NOTLOGGED */
+#endif
 } VNode;
 
 
@@ -411,6 +440,11 @@
 #define NODE_DELTED		4
 #define NODE_OBSOLETE		8
 
+#ifdef VERSECHAT
+#define CHAT_NOTLOGGED		0
+#define CHAT_LOGGED		1
+#endif
+
 /* VLayer flags */
 #define LAYER_SENT		1
 #define LAYER_RECEIVED		2
@@ -482,7 +516,7 @@
 struct VerseSession *create_verse_session(const char *name, const char *pass, const char *address, uint8 *expected_key);
 void free_verse_session(struct VerseSession *session);
 void b_verse_update(void);
-void b_vers_ms_get(void);
+void b_verse_ms_get(void);
 void b_verse_connect(char *address);
 void end_verse_session(struct VerseSession *session);
 void end_all_verse_sessions(void);
@@ -493,6 +527,7 @@
 void send_verse_node(struct VNode *vnode);
 void free_verse_node_data(struct VNode *vnode);
 void free_verse_node(struct VNode *vnode);
+struct VNode* lookup_vnode(VerseSession *session, VNodeID node_id);
 struct VNode* create_verse_node(VerseSession *session, VNodeID node_id, uint8 type, VNodeID owner_id);
 void set_node_callbacks(void);
 
@@ -508,7 +543,19 @@
 void free_object_data(struct VNode *vnode);
 void set_object_callbacks(void);
 struct VObjectData *create_object_data(void);
+	
 
+/* functions from verse_method.c */
+void free_verse_methodgroup(VMethodGroup *vmg);
+#ifdef VERSECHAT
+void send_say(const char *chan, const char *utter);
+void send_login(struct VNode *vnode);
+void send_logout(struct VNode *vnode);
+void send_join(struct VNode *vnode, const char *chan);
+void send_leave(struct VNode *vnode, const char *chan);
+#endif
+void set_method_callbacks(void);
+
 /* functions from verse_geometry_node.c */
 struct VerseFace* create_verse_face(struct VLayer *vlayer, uint32 polygon_id, uint32 v0, uint32 v1, uint32 v2, uint32 v3);
 struct VerseVert* create_verse_vertex(struct VLayer *vlayer, uint32 vertex_id, real32 x, real32 y, real32 z);

Added: trunk/blender/source/blender/blenkernel/intern/verse_method.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/verse_method.c	                        (rev 0)
+++ trunk/blender/source/blender/blenkernel/intern/verse_method.c	2007-06-11 10:42:38 UTC (rev 10916)
@@ -0,0 +1,523 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contributor(s): Nathan Letwory. 
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#ifdef WITH_VERSE
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+#include "DNA_userdef_types.h"
+#include "DNA_text_types.h"
+
+#include "BLI_dynamiclist.h"
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+
+#include "BIF_verse.h"
+
+#include "BKE_bad_level_calls.h"
+#include "BKE_library.h"
+#include "BKE_text.h"
+#include "BKE_verse.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+
+#include "verse.h"
+
+/* helper struct for creating method descriptions */
+typedef struct VMethodInfo {
+	const char *name;
+	uint8 param_count;
+	const VNOParamType param_type[4];
+	const char *param_name[4];
+	uint16 id;
+} VMethodInfo;
+
+#ifdef VERSECHAT
+/* array with methods for verse chat */
+static VMethodInfo vmethod_info[] = {
+	{ "join", 1, { VN_O_METHOD_PTYPE_STRING }, { "channel"}},
+	{ "leave", 1, { VN_O_METHOD_PTYPE_STRING }, { "channel"}},
+	{ "hear", 3, { VN_O_METHOD_PTYPE_STRING, VN_O_METHOD_PTYPE_STRING, VN_O_METHOD_PTYPE_STRING }, { "channel", "from", "msg"}}
+};
+#endif
+
+/* lookup a method group based on its name */
+struct VMethodGroup *lookup_vmethodgroup_name(ListBase *lb, const char *name) {
+	struct VMethodGroup *vmg;
+
+	for(vmg= lb->first; vmg; vmg= vmg->next)
+		if(strcmp(vmg->name,name)==0) break;
+	
+	return vmg;
+}
+
+/* lookup a method group based on its group_id */
+struct VMethodGroup *lookup_vmethodgroup(ListBase *lb, uint16 group_id) {
+	struct VMethodGroup *vmg;
+
+	for(vmg= lb->first; vmg; vmg= vmg->next)
+		if(vmg->group_id==group_id) break;
+	
+	return vmg;
+}
+
+/* lookup a method based on its name */
+struct VMethod *lookup_vmethod_name(ListBase *lb, const char *name) {
+	struct VMethod *vm;
+	for(vm= lb->first; vm; vm= vm->next)
+		if(strcmp(vm->name,name)==0) break;
+
+	return vm;
+}
+
+/* lookup a method based on its method_id */
+struct VMethod *lookup_vmethod(ListBase *lb, uint8 method_id) {
+	struct VMethod *vm;
+	for(vm= lb->first; vm; vm= vm->next)
+		if(vm->id==method_id) break;
+
+	return vm;
+}
+
+#ifdef VERSECHAT
+/*
+ * send say command
+ */
+void send_say(const char *chan, const char *utter)
+{
+	struct VerseSession *session = (VerseSession*)current_verse_session();
+	struct VNode *vnode;
+	struct VMethodGroup *vmg;
+	struct VMethod *vm;
+	VNOPackedParams *utterpack;
+	VNOParam args[2];
+	
+	vnode= (VNode *)(session->nodes.lb.first);
+
+	for( ; vnode; vnode= vnode->next) {
+		if(strcmp(vnode->name, "tawksrv")==0) {
+			vmg= lookup_vmethodgroup_name(&(vnode->methodgroups), "tawk");
+			if(!vmg) break;
+			vm= lookup_vmethod_name(&(vmg->methods), "say");
+			if(!vm) break;
+			args[0].vstring= (char *)chan;
+			args[1].vstring= (char *)utter;
+			if((utterpack= verse_method_call_pack(vm->param_count, vm->param_type, args))!=NULL) {
+				verse_send_o_method_call(vnode->id, vmg->group_id, vm->id, vnode->session->avatar, utterpack);
+			}
+			break;
+		}
+
+	}
+}
+
+/*
+ * send logout command
+ */
+void send_logout(VNode *vnode)
+{
+	struct VMethodGroup *vmg;
+	struct VMethod *vm;
+	VNOPackedParams *pack;
+
+	vnode->chat_flag = CHAT_LOGGED;
+	vmg= lookup_vmethodgroup_name(&(vnode->methodgroups), "tawk");
+	if(!vmg) return;
+	vm= lookup_vmethod_name(&(vmg->methods), "logout");
+	if(!vm) return;
+
+	if((pack= verse_method_call_pack(vm->param_count, vm->param_type, NULL))!=NULL) {
+		verse_send_o_method_call(vnode->id, vmg->group_id, vm->id, vnode->session->avatar, pack);
+	}
+	vnode->chat_flag = CHAT_NOTLOGGED;
+}
+
+/*
+ * send join command
+ */
+void send_join(VNode *vnode, const char *chan)
+{
+	struct VMethodGroup *vmg;
+	struct VMethod *vm;
+	VNOPackedParams *join;
+	VNOParam channel[1];
+
+	vmg= lookup_vmethodgroup_name(&(vnode->methodgroups), "tawk");
+	if(!vmg) return;
+	vm= lookup_vmethod_name(&(vmg->methods), "join");
+	if(!vm) return;
+
+	channel[0].vstring= (char *)chan;
+	if((join= verse_method_call_pack(vm->param_count, vm->param_type, channel))!=NULL) {
+		verse_send_o_method_call(vnode->id, vmg->group_id, vm->id, vnode->session->avatar, join);
+	}
+}
+
+/*
+ * send leave command
+ */
+void send_leave(VNode *vnode, const char *chan)
+{
+	struct VMethodGroup *vmg;
+	struct VMethod *vm;
+	VNOPackedParams *leave;
+	VNOParam channel[1];
+
+	vmg= lookup_vmethodgroup_name(&(vnode->methodgroups), "tawk");
+	if(!vmg) return;
+	vm= lookup_vmethod_name(&(vmg->methods), "leave");
+	if(!vm) return;
+
+	channel[0].vstring= (char *)chan;
+	if((leave= verse_method_call_pack(vm->param_count, vm->param_type, channel))!=NULL) {
+		verse_send_o_method_call(vnode->id, vmg->group_id, vm->id, vnode->session->avatar, leave);
+	}
+}
+
+/*
+ * send login command
+ */
+void send_login(VNode *vnode)
+{
+	struct VMethodGroup *vmg;
+	struct VMethod *vm;
+	VNOPackedParams *login;
+	VNOParam param[1];
+
+	vnode->chat_flag = CHAT_LOGGED;
+	vmg= lookup_vmethodgroup_name(&(vnode->methodgroups), "tawk");
+	if(!vmg) return;
+	vm= lookup_vmethod_name(&(vmg->methods), "login");
+	if(!vm) return;
+
+	param[0].vstring= U.verseuser;
+
+	if((login= verse_method_call_pack(vm->param_count, vm->param_type, param))!=NULL) {
+		verse_send_o_method_call(vnode->id, vmg->group_id, vm->id, vnode->session->avatar, login);
+	}
+	vnode->chat_flag = CHAT_LOGGED;
+
+	vnode= lookup_vnode(vnode->session, vnode->session->avatar);
+	vmg= lookup_vmethodgroup_name(&(vnode->methodgroups), "tawk-client");
+	if(!vmg)
+		verse_send_o_method_group_create(vnode->session->avatar, ~0, "tawk-client");
+}
+#endif
+
+/*
+ * Free a VMethod
+ */
+void free_verse_method(VMethod *vm) {
+	if(!vm) return;
+
+	MEM_freeN(vm->param_type);
+}
+
+/*
+ * Free methods for VMethodGroup
+ */
+void free_verse_methodgroup(VMethodGroup *vmg)
+{
+	struct VMethod *vm, *tmpvm;
+
+	if(!vmg) return;
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list