2 #include <G3D/G3DAll.h>
3 #include <GLG3D/GLG3D.h>
8 #if defined(G3D_VER) && (G3D_VER < 70000)
9 # error Requires G3D 7.00
17 static cl_object
cl_write_text_to_g3d(cl_object array
)
20 GConsole::string to_write
;
22 cl_object i_index
= ecl_make_unsigned_integer(0);
23 cl_object dim
= cl_array_dimension(array
, i_index
);
24 cl_fixnum dim_fixnum
= ecl_to_fixnum( dim
);
25 cl_object i_fixnum
= ecl_make_unsigned_integer(0);
26 for( int i
= 0; i
< dim_fixnum
; i
++ )
28 i_fixnum
= ecl_make_unsigned_integer(i
);
29 cl_object ecl_char
= cl_row_major_aref(array
, i_fixnum
);
31 // possible encoding nightmare ahoy!
32 // Need to transcode as whatever g3d uses
33 if ((CHARACTERP(ecl_char
)) && (cl_graphic_char_p(ecl_char
))) {
34 char c
= ecl_to_char(ecl_char
);
35 to_write
.push_back(c
);
39 g_theApp
->console
->print(to_write
);
43 inline cl_object
symbol(char *str
)
45 return cl_intern(1, make_simple_base_string(str
));
49 cl_object g_eval_handler
;
51 cl_object g_readErrorSymbol
;
52 cl_object g_evalErrorSymbol
;
54 bool isError(cl_object obj
, const char ** errorMessage
)
58 if (obj
== g_readErrorSymbol
)
60 *errorMessage
= "Error reading form";
62 else if (obj
== g_evalErrorSymbol
)
64 *errorMessage
= "Error evaluating form";
67 return obj
== g_readErrorSymbol
|| obj
== g_evalErrorSymbol
;
70 // Construct a function call to safely do the read operation.
71 cl_object
safeRead(const std::string
& strCmd
)
73 cl_object command
= make_simple_base_string((char*)strCmd
.c_str());
74 cl_object readFromStringSymbol
= c_string_to_object("READ-FROM-STRING");
75 // The form looks like this:
76 // ( 'read-from-string . ( <our command> . nil ) )
77 // By constructing it manually we don't have to worry about escaping.
78 cl_object form
= CONS(readFromStringSymbol
,
80 // Evaluate the built up read form.
81 cl_object read
= si_safe_eval(3, form
, Cnil
, g_readErrorSymbol
);
85 int main(int argc
, char** argv
) {
87 GApp::Settings settings
;
89 const char *handler
= "#.(lambda (str env err-value) (multiple-value-list (catch 'si::protect-tag (let* ((*debugger-hook* #'(lambda (condition old-hooks) (throw 'si::protect-tag condition)))) (si::eval-with-env (read-from-string str) env)))))";
92 ecl_register_static_root(&g_eval_handler
);
93 g_eval_handler
= c_string_to_object(handler
);
95 g_readErrorSymbol
= cl_gensym(0);
96 g_evalErrorSymbol
= cl_gensym(0);
98 si_select_package(make_simple_base_string("CL-USER"));
100 cl_def_c_function(symbol("WRITE-TEXT-TO-G3D"), /* uppercase! */
101 (void *)cl_write_text_to_g3d
,
104 cl_def_c_function(symbol("MAKE-SPHERE-ENTITY"),
105 (void *) cl_make_sphere_entity
,
108 cl_def_c_function(symbol("MAKE-BOX-ENTITY"),
109 (void *) cl_make_box_entity
,
112 cl_def_c_function(symbol("MAKE-AXES-ENTITY"),
113 (void *) cl_make_axes_entity
,
116 cl_def_c_function(symbol("ENTITY-ORIENTATION"),
117 (void *) cl_get_entity_orientation
,
120 cl_def_c_function(symbol("ENTITY-POSITION"),
121 (void *) cl_get_entity_position
,
124 cl_def_c_function(symbol("SET-ENTITY-ORIENTATION"),
125 (void *) cl_set_entity_orientation
,
128 cl_def_c_function(symbol("SET-ENTITY-POSITION"),
129 (void *) cl_set_entity_position
,
132 cl_def_c_function(symbol("GET-ENTITY-WIRE-COLOUR"),
133 (void*) cl_set_entity_wire_color
,
136 cl_def_c_function(symbol("SET-ENTITY-WIRE-COLOUR"),
137 (void*) cl_set_entity_wire_color
,
140 cl_def_c_function(symbol("GET-ENTITY-SOLID-COLOUR"),
141 (void*) cl_set_entity_solid_color
,
144 cl_def_c_function(symbol("SET-ENTITY-SOLID-COLOUR"),
145 (void*) cl_set_entity_solid_color
,
148 g_theApp
= new App(settings
);