FreeWRL / FreeX3D 4.3.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
24CdllFreeWRL::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
48void 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}
56void CdllFreeWRL::onInitArgv(int argc, char **argv, bool frontend_handles_display_thread)
57{
58 int FEHDT = frontend_handles_display_thread ? 1 : 0;
59 dllFreeWRL_onInitArgv(this->globalcontexthandle, argc, argv, FEHDT);
60 return;
61}
62void CdllFreeWRL::setDensityFactor(float density_factor)
63{
64 dllFreeWRL_setDensityFactor(this->globalcontexthandle, density_factor);
65 return;
66}
67void CdllFreeWRL::setTempFolder(char *tmpFolder)
68{
69 dllFreeWRL_setTempFolder(this->globalcontexthandle, tmpFolder);
70}
71void CdllFreeWRL::setFontFolder(char *fontFolder)
72{
73 dllFreeWRL_setFontFolder(this->globalcontexthandle, fontFolder);
74}
75CdllFreeWRL::CdllFreeWRL(int width, int height, void* windowhandle, bool bEai)
76{
77 int BEai;
78 BEai = bEai ? 1 : 0;
79 this->globalcontexthandle = dllFreeWRL_dllFreeWRL1(width, height, windowhandle, BEai);
80}
81CdllFreeWRL::CdllFreeWRL(char* scene_url, int width, int height, void* windowhandle, bool bEai)
82{
83 int BEai;
84 BEai = bEai ? 1 : 0;
85 this->globalcontexthandle = dllFreeWRL_dllFreeWRL2(scene_url, width, height, windowhandle, BEai);
86}
87
88void CdllFreeWRL::onLoad(char* scene_url)
89{
90 dllFreeWRL_onLoad(this->globalcontexthandle, scene_url);
91}
92
93void CdllFreeWRL::onResize(int width,int height){
94 dllFreeWRL_onResize(this->globalcontexthandle, width, height);
95}
96
97int CdllFreeWRL::onMouse(int mouseAction,int mouseButton,int x, int y)
98{
99 return dllFreeWRL_onMouse(this->globalcontexthandle, mouseAction,mouseButton, x, y);
100}
101int CdllFreeWRL::onTouch(int touchAction, unsigned int ID, int x, int y)
102{
103 return dllFreeWRL_onTouch(this->globalcontexthandle, touchAction, ID, x, y);
104}
105void CdllFreeWRL::onAccelerometer(float ax, float ay, float az){
106 return dllFreeWRL_onAccelerometer(this->globalcontexthandle, ax, ay, az);
107}
108void CdllFreeWRL::onGyro(float rx, float ry, float rz) {
109 return dllFreeWRL_onGyro(this->globalcontexthandle, rx, ry, rz);
110}
111void CdllFreeWRL::onMagnetic(float azimuth, float pitch, float roll) {
112 return dllFreeWRL_onMagnetic(this->globalcontexthandle, azimuth,pitch,roll);
113}
114
115void CdllFreeWRL::onKey(int keyAction,int keyValue)
116{
117 dllFreeWRL_onKey(this->globalcontexthandle, keyAction, keyValue);
118}
119void CdllFreeWRL::onClose()
120{
121 dllFreeWRL_onClose(this->globalcontexthandle);
122}
123void CdllFreeWRL::print(char *str)
124{
125 dllFreeWRL_print(this->globalcontexthandle, str);
126}
127void CdllFreeWRL::onDraw()
128{
129 dllFreeWRL_onDraw(this->globalcontexthandle);
130}
131
132int CdllFreeWRL::getUpdatedCursorStyle()
133{
134 return dllFreeWRL_getUpdatedCursorStyle(this->globalcontexthandle);
135}
136void* CdllFreeWRL::frontenditem_dequeue()
137{
138 return dllFreeWRL_frontenditem_dequeue(this->globalcontexthandle);
139}
140char* CdllFreeWRL::resitem_getURL(void *res)
141{
142 return dllFreeWRL_resitem_getURL(this->globalcontexthandle, res);
143}
144int CdllFreeWRL::resitem_getStatus(void *res)
145{
146 return dllFreeWRL_resitem_getStatus(this->globalcontexthandle, res);
147}
148void CdllFreeWRL::resitem_setStatus(void *res, int status){
149 dllFreeWRL_resitem_setStatus(this->globalcontexthandle, res, status);
150}
151
152int CdllFreeWRL::resitem_getType(void *res)
153{
154 return dllFreeWRL_resitem_getType(this->globalcontexthandle, res);
155}
156int CdllFreeWRL::resitem_getMediaType(void *res)
157{
158 return dllFreeWRL_resitem_getMediaType(this->globalcontexthandle, res);
159}
160
161void CdllFreeWRL::resitem_enqueuNextMulti(void *res){
162 dllFreeWRL_resitem_enqueuNextMulti(this->globalcontexthandle, res);
163}
164void CdllFreeWRL::resitem_setLocalPath(void *res, char* path)
165{
166 dllFreeWRL_resitem_setLocalPath(this->globalcontexthandle, res, path);
167}
168void CdllFreeWRL::resitem_load(void *res)
169{
170 dllFreeWRL_resitem_load(this->globalcontexthandle, res);
171}
172void CdllFreeWRL::resitem_enqueue(void *res){
173 dllFreeWRL_resitem_enqueue(this->globalcontexthandle, res);
174}
175void CdllFreeWRL::commandline(char *cmdline){
176 dllFreeWRL_commandline(this->globalcontexthandle, cmdline);
177}
178