FreeWRL/FreeX3D  3.0.0
dllFreeWRL.cpp
1 /* dllFreeWRL.cpp : Defines the exported functions for the DLL application.
2  general notes:
3  Your main program -or html page- defines a single process and main thread.
4  If you want to have more than one instance of freewrl (separate window and content)
5  in the same process, then you need to connect the 'context' to the thread
6  functionality. But your main program is all in one thread. So you can't just use
7  your main thread to select a context.
8  Here we'll use a pointer to iglobal as a context handle.
9 
10 */
11 
12 
13 
14 #include "dllFreeWRL.h"
15 #define DELEGATE_TO_C 1
16 #ifdef DELEGATE_TO_C
17 #include "cdllFreeWRL.h"
18 #endif
19 
20 // This is the constructor of a class that has been exported.
21 // see dllFreeWRL.h for the class definition
22 
23 
24 CdllFreeWRL::CdllFreeWRL()
25 {
26  /*STA -single threaded app- frontends -like web pages in a browser, .net forms, xaml apps-
27  can have multiple freewrl instances in different sub-windows, all running
28  in the same frontend thread. But then we can't rely on thread-lookup
29  to find which freewrl instance. But the frontend developer will have
30  a pointer to each instance. Then we look up the freewrl instance from that,
31  using this->globalcontexthandle, fwl_setCurrentHandle(), fwl_clearCurrentHandle(),
32  for the frontend-thread-synchronized part (functions called from the STA), and then
33  worker threads within libfreewrl can use thread lookup to get the global instance
34  for the backend parts. No thread locking is needed in the frontend-thread-sync part
35  -like here in dllfreewrl.cpp- because the frontend developer will program against
36  one dllfreewrl instance at a time due to it being STA.
37  If converting this cdllfreewrl C++ to flat C interface, then add an extra
38  parameter void* fwglobal to all the functions, do fwl_init_instance in the constructor
39  and have it return the gglobal as void *, and the frontend programmer will hold
40  the fwglobal pointer between calls.
41  */
42  //this->globalcontexthandle = 0;
43  this->globalcontexthandle = dllFreeWRL_dllFreeWRL(); //before setting any structs we need a struct allocated
44 }
45 // handle - window handle or null
46 // - if you have a window already created, you should pass in the handle,
47 // - else pass null and a window will be created for you
48 void CdllFreeWRL::onInit(int width, int height, void* windowhandle, bool bEai, bool frontend_handles_display_thread)
49 {
50  int BEai, FEHDT;
51  FEHDT = frontend_handles_display_thread ? 1 : 0;
52  BEai = bEai ? 1 : 0;
53  dllFreeWRL_onInit(this->globalcontexthandle, width, height, windowhandle, BEai, FEHDT);
54  return;
55 }
56 void CdllFreeWRL::setDensityFactor(float density_factor)
57 {
58  dllFreeWRL_setDensityFactor(this->globalcontexthandle, density_factor);
59  return;
60 }
61 void CdllFreeWRL::setTempFolder(char *tmpFolder)
62 {
63  dllFreeWRL_setTempFolder(this->globalcontexthandle, tmpFolder);
64 }
65 void CdllFreeWRL::setFontFolder(char *fontFolder)
66 {
67  dllFreeWRL_setFontFolder(this->globalcontexthandle, fontFolder);
68 }
69 CdllFreeWRL::CdllFreeWRL(int width, int height, void* windowhandle, bool bEai)
70 {
71  int BEai;
72  BEai = bEai ? 1 : 0;
73  this->globalcontexthandle = dllFreeWRL_dllFreeWRL1(width, height, windowhandle, BEai);
74 }
75 CdllFreeWRL::CdllFreeWRL(char* scene_url, int width, int height, void* windowhandle, bool bEai)
76 {
77  int BEai;
78  BEai = bEai ? 1 : 0;
79  this->globalcontexthandle = dllFreeWRL_dllFreeWRL2(scene_url, width, height, windowhandle, BEai);
80 }
81 
82 void CdllFreeWRL::onLoad(char* scene_url)
83 {
84  dllFreeWRL_onLoad(this->globalcontexthandle, scene_url);
85 }
86 
87 
88 void CdllFreeWRL::onResize(int width,int height){
89  dllFreeWRL_onResize(this->globalcontexthandle, width, height);
90 }
91 
92 int CdllFreeWRL::onMouse(int mouseAction,int mouseButton,int x, int y)
93 {
94  return dllFreeWRL_onMouse(this->globalcontexthandle, mouseAction,mouseButton, x, y);
95 }
96 int CdllFreeWRL::onTouch(int touchAction, unsigned int ID, int x, int y)
97 {
98  return dllFreeWRL_onTouch(this->globalcontexthandle, touchAction, ID, x, y);
99 }
100 void CdllFreeWRL::onAccelerometer(float ax, float ay, float az){
101  return dllFreeWRL_onAccelerometer(this->globalcontexthandle, ax, ay, az);
102 }
103 void CdllFreeWRL::onGyro(float rx, float ry, float rz) {
104  return dllFreeWRL_onGyro(this->globalcontexthandle, rx, ry, rz);
105 }
106 void CdllFreeWRL::onMagnetic(float azimuth, float pitch, float roll) {
107  return dllFreeWRL_onMagnetic(this->globalcontexthandle, azimuth,pitch,roll);
108 }
109 
110 void CdllFreeWRL::onKey(int keyAction,int keyValue)
111 {
112  dllFreeWRL_onKey(this->globalcontexthandle, keyAction, keyValue);
113 }
114 void CdllFreeWRL::onClose()
115 {
116  dllFreeWRL_onClose(this->globalcontexthandle);
117 }
118 void CdllFreeWRL::print(char *str)
119 {
120  dllFreeWRL_print(this->globalcontexthandle, str);
121 }
122 void CdllFreeWRL::onDraw()
123 {
124  dllFreeWRL_onDraw(this->globalcontexthandle);
125 }
126 
127 int CdllFreeWRL::getUpdatedCursorStyle()
128 {
129  return dllFreeWRL_getUpdatedCursorStyle(this->globalcontexthandle);
130 }
131 void* CdllFreeWRL::frontenditem_dequeue()
132 {
133  return dllFreeWRL_frontenditem_dequeue(this->globalcontexthandle);
134 }
135 char* CdllFreeWRL::resitem_getURL(void *res)
136 {
137  return dllFreeWRL_resitem_getURL(this->globalcontexthandle, res);
138 }
139 int CdllFreeWRL::resitem_getStatus(void *res)
140 {
141  return dllFreeWRL_resitem_getStatus(this->globalcontexthandle, res);
142 }
143 void CdllFreeWRL::resitem_setStatus(void *res, int status){
144  dllFreeWRL_resitem_setStatus(this->globalcontexthandle, res, status);
145 }
146 
147 int CdllFreeWRL::resitem_getType(void *res)
148 {
149  return dllFreeWRL_resitem_getType(this->globalcontexthandle, res);
150 }
151 int CdllFreeWRL::resitem_getMediaType(void *res)
152 {
153  return dllFreeWRL_resitem_getMediaType(this->globalcontexthandle, res);
154 }
155 
156 void CdllFreeWRL::resitem_enqueuNextMulti(void *res){
157  dllFreeWRL_resitem_enqueuNextMulti(this->globalcontexthandle, res);
158 }
159 void CdllFreeWRL::resitem_setLocalPath(void *res, char* path)
160 {
161  dllFreeWRL_resitem_setLocalPath(this->globalcontexthandle, res, path);
162 }
163 void CdllFreeWRL::resitem_load(void *res)
164 {
165  dllFreeWRL_resitem_load(this->globalcontexthandle, res);
166 }
167 void CdllFreeWRL::resitem_enqueue(void *res){
168  dllFreeWRL_resitem_enqueue(this->globalcontexthandle, res);
169 }
170 void CdllFreeWRL::commandline(char *cmdline){
171  dllFreeWRL_commandline(this->globalcontexthandle, cmdline);
172 }
173