Release s3d 0.2.2
[s3d.git] / server / mcp.c
blob73386085b0c8b8660c2cdf25ae535c3b63d2181f
1 /*
2 * mcp.c
4 * Copyright (C) 2004-2011 Simon Wunderlich <dotslash@packetmixer.de>
6 * This file is part of s3d, a 3d network display server.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * s3d is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with s3d; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "global.h"
25 #include "proto.h" /* for S3D_P_OBJECT, to be integrated in proto.c */
26 #ifdef WIN32
27 #include <winsock2.h>
28 #else
29 #include <netinet/in.h> /* htonl() */
30 #endif
31 #include <string.h> /* strncpy() */
33 /* this interacts with the actual mcp client */
34 struct mcp_object {
35 uint32_t object;
36 float trans_x, trans_y, trans_z;
37 float r;
38 /* char event; */
39 char name[S3D_NAME_MAX];
42 #define MCP_NEW_OBJECT 1
44 /* call when a new mcp connects */
45 int mcp_init(void)
47 struct t_process *p;
48 uint32_t i;
49 p = get_proc_by_pid(MCP);
50 i = p->n_obj;
51 while (i--) {
52 if (p->object[i] != NULL)
53 switch (p->object[i]->oflags & OF_TYPE) {
54 case OF_VIRTUAL:
55 mcp_rep_object(i);
56 break;
57 case OF_CAM:
58 event_obj_info(p, i);
59 break;
62 mcp_focus(-1);
63 return 0;
66 /* report the mcp about our object */
67 int mcp_rep_object(int32_t mcp_oid)
69 struct mcp_object mo;
70 struct t_process *p, *ap;
71 p = get_proc_by_pid(MCP);
72 mo.object = htonl(mcp_oid);
73 mo.trans_x = p->object[mcp_oid]->translate.x;
74 mo.trans_y = p->object[mcp_oid]->translate.y;
75 mo.trans_z = p->object[mcp_oid]->translate.z;
76 mo.r = p->object[mcp_oid]->r;
78 htonfb(&mo.trans_x, 4);
79 ap = get_proc_by_pid(p->object[mcp_oid]->virtual_pid);
80 strncpy(mo.name, ap->name, S3D_NAME_MAX);
81 prot_com_out(p, S3D_P_MCP_OBJECT, (uint8_t *) & mo, sizeof(struct mcp_object));
82 return 0;
85 /* tells the mcp that some program vanished ... */
86 int mcp_del_object(int32_t mcp_oid)
88 int32_t oid = htonl(mcp_oid);
89 if (mcp_oid == focus_oid) {
90 s3dprintf(MED, "lost the focus of mcp-oid %d", mcp_oid);
91 mcp_focus(-1);
93 prot_com_out(get_proc_by_pid(MCP), S3D_P_MCP_DEL_OBJECT, (uint8_t *) & oid, 4);
94 return 0;
97 /* sets a new focus */
98 int mcp_focus(int oid)
100 struct t_process *p;
101 struct t_obj *o;
102 focus_oid = -1;
103 p = get_proc_by_pid(MCP);
104 s3dprintf(MED, "request to focus %d", oid);
105 if (OBJ_VALID(p, oid, o))
106 if (o->oflags & OF_VIRTUAL) {
107 focus_oid = oid;
108 obj_pos_update(p, 0, 0);
110 return 0;