SO3Engine
SCOLLog.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 SO3Engine : Wrapper Ogre for SCOL
27 First version : nov 2008
28*/
29
37#include "SCOLPack/SO3SCOL.h"
38
39// Renderer includes
40#include "SO3Renderer/SO3Root.h"
42
45
46
47class ScolLogEventsListener : public SLogListener
48{
49public:
50protected:
51private:
52
53public:
56 ScolLogEventsListener()
57 {
58 };
59
60 virtual void messageLogged(const Ogre::String& message)
61 {
62 char* cmess = (char*)malloc(sizeof(char*) * (message.length() + 1));
63 std::strcpy(cmess, message.c_str());
64
65 OBJpostEvent(SO3_LOGS_MSG, SCOL_PTR SRoot::getSingletonPtr(), SCOL_PTR cmess);
66 }
67
68protected:
69private:
70};
71
72
76ScolLogEventsListener* scolLogEventsListener = 0;
77
78
87int destroyLogs(mmachine m, SCOL_PTR_TYPE handle, int obj)
88{
89#ifdef SO3_DEBUG
90 MMechostr(MSKDEBUG, "destroyLogs \n");
91#endif
92
93 SRoot::getSingleton().SetLogEnable(false);
94 MMsetPointer<SRoot*>(m, MTOP(obj), 0);
95 return 0;
96}
97
98
110int getLogCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
111{
112#ifdef SO3_DEBUG
113 MMechostr(MSKDEBUG, "getLogCallback\n");
114#endif
115
116 int k = 0;
117 int obj = 0;
118
119 if (SRoot::getSingletonPtr() == 0)
120 return -1;
121
122 // equal to OBJbeginreflex
123 // is there a callback assigned to the object?
124 obj = OBJfindTH(m, SO3LOGS, id);
125 if (obj == NIL)
126 return -1;
127
128 if (MMfetch(m, obj, OFFOBJREF0 + SO3_LOGS_CB * 2) == NIL)
129 return -1;
130
131 //equal to OBJpreparereflex but replace the object
132 //set the current channel
133 MMsetglobal(m, OFFSCCUR, MMfetch(m, obj, OFFOBJCHN));
134 if (MMpush(m, MMgetglobal(m, OFFSCCUR))) return MERRMEM;
135
136 //push the callback ptr
137 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_LOGS_CB * 2))) return MERRMEM;
138
139 // replace the object by the log message
140 if (Mpushstrbloc(m, (char*)param)) return MERRMEM;
141
142 //push the user parameter
143 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_LOGS_CB * 2 + 1))) return MERRMEM;
144
145 free((char*)param);
146 return OBJcallreflex(m, 0);
147}
148
149
162int SO3CbLogs(mmachine m)
163{
164#ifdef SO3_DEBUG
165 MMechostr(MSKDEBUG, "SO3CbSceneLog\n");
166#endif
167
168 int flag = MMpull(m);
169 int p = MMpull(m);
170 int reflex = MMpull(m);
171 int chan = MMget(m, 0);
172
173 if (chan == NIL)
174 {
175 MMset(m, 0, NIL);
176 return 0;
177 }
178
179 if (SRoot::getSingletonPtr() == 0)
180 {
181 MMset(m, 0, NIL);
182 return 0;
183 }
184
185 int n = OBJfindTH(m, SO3LOGS, SCOL_PTR SRoot::getSingletonPtr());
186 if (n != NIL)
187 {
188 n = MMfetch(m, n, OFFOBJMAG);
189 MMset(m, 0, n);
190 }
191 else
192 {
193 if ((MMpushPointer(m, SRoot::getSingletonPtr()) != 0))
194 {
195 MMset(m, 0, NIL);
196 return MERRMEM;
197 }
198
199 OBJcreate(m, SO3LOGS, SCOL_PTR SRoot::getSingletonPtr(), NIL, 0);
200 }
201
202
203 Ogre::LogMessageLevel logFlag = Ogre::LML_NORMAL;
204 if (flag != NIL)
205 logFlag = (Ogre::LogMessageLevel)MTOI(flag);
206
207 SRoot::getSingleton().SetLogMask(logFlag);
208 SRoot::getSingleton().SetLogEnable(reflex == NIL ? false : true);
209
210 MMpush(m, reflex);
211 MMpush(m, p);
212
213 OBJaddreflex(m, SO3LOGS, SO3_LOGS_CB);
214
215 MMset(m, 0, ITOM(1));
216
217 return 0;
218}
219
220
221NativeDefinition natSO3Log[] = {
222 { "SO3Logs", TYPTYPE, NULL, NULL },
223 { "SO3CbLogs", 4, "fun [Chn fun [S u0] u1 u0 I] I", SO3CbLogs }
224};
225
226
232int SCOLloadLogs(mmachine m, cbmachine w)
233{
234 scolLogEventsListener = new ScolLogEventsListener();
235 SRoot::getSingleton().AddLogListener(scolLogEventsListener);
236
237 SO3LOGS = OBJregister(1, 1, destroyLogs, "SO3_LOGS");
238
239 SO3_LOGS_MSG = OBJgetUserEvent();
240 OBJdefEvent(SO3_LOGS_MSG, getLogCallback);
241 return PKhardpak2(m, "SO3Log.pkg", sizeof(natSO3Log) / sizeof(natSO3Log[0]), natSO3Log);
242}
243
244
250{
251 SRoot::getSingleton().RemoveLogListener(scolLogEventsListener);
252 SO3_SAFE_DELETE(scolLogEventsListener);
253 return 0;
254}
ScolLogEventsListener * scolLogEventsListener
Definition SCOLLog.cpp:76
int getLogCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the Scene Log event callback.
Definition SCOLLog.cpp:110
int SO3_LOGS_MSG
Definition SCOLLog.cpp:44
int SO3LOGS
main include
Definition SCOLLog.cpp:43
int destroyLogs(mmachine m, SCOL_PTR_TYPE handle, int obj)
function to destroy an SO3_LOGS in scol
Definition SCOLLog.cpp:87
int SCOLloadLogs(mmachine m, cbmachine w)
Load the SO3Engine Logs function.
Definition SCOLLog.cpp:232
NativeDefinition natSO3Log[]
Definition SCOLLog.cpp:221
int SCOLfreeLogs()
free the SO3Engine Logs function
Definition SCOLLog.cpp:249
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
SCOL_EXPORT void SCOL_PTR_TYPE param
Definition SO3SCOL.cpp:5089
int SO3CbLogs(mmachine m)
SO3CbLogs : Define the callback scol had to be called when there is a log event.
Definition SCOLLog.cpp:162