OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "embedders/openglui/emulator/emulator_embedder.h" |
| 6 |
| 7 #include <string.h> |
| 8 |
| 9 #include "embedders/openglui/common/context.h" |
| 10 #include "embedders/openglui/common/dart_host.h" |
| 11 #include "embedders/openglui/common/events.h" |
| 12 #include "embedders/openglui/common/input_handler.h" |
| 13 #include "embedders/openglui/common/sound_handler.h" |
| 14 #include "embedders/openglui/common/vm_glue.h" |
| 15 #include "embedders/openglui/emulator/emulator_graphics_handler.h" |
| 16 |
| 17 InputHandler* input_handler_ptr; |
| 18 LifeCycleHandler* lifecycle_handler_ptr; |
| 19 |
| 20 void display() { |
| 21 glClearColor(1.0, 1.0, 1.0, 1.0); |
| 22 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 23 lifecycle_handler_ptr->OnStep(); |
| 24 glutSwapBuffers(); |
| 25 } |
| 26 |
| 27 void reshape(int width, int height) { |
| 28 glViewport(0, 0, width, height); |
| 29 glMatrixMode(GL_PROJECTION); |
| 30 glLoadIdentity(); |
| 31 glOrtho(0, width, 0, height, -1, 1); |
| 32 glMatrixMode(GL_MODELVIEW); |
| 33 glutPostRedisplay(); |
| 34 } |
| 35 |
| 36 void keyboard(unsigned char key, int x, int y) { |
| 37 input_handler_ptr->OnKeyEvent(kKeyDown, time(0), 0, key, 0, 0); |
| 38 input_handler_ptr->OnKeyEvent(kKeyUp, time(0), 0, key, 0, 0); |
| 39 if (key == 27) { |
| 40 exit(0); |
| 41 } |
| 42 } |
| 43 |
| 44 DART_EXPORT void emulator_main(int argc, char** argv, const char* script) { |
| 45 EmulatorGraphicsHandler graphics_handler(argc, argv); |
| 46 if (argc > 0) { |
| 47 int i = argc - 1; |
| 48 size_t len = strlen(argv[i]); |
| 49 if (len > 5 && strcmp(".dart", argv[i] + len - 5) == 0) { |
| 50 script = argv[i]; |
| 51 } |
| 52 } |
| 53 VMGlue vm_glue(&graphics_handler, ".", "gl.dart", script); |
| 54 InputHandler input_handler(&vm_glue); |
| 55 input_handler_ptr = &input_handler; |
| 56 SoundHandler sound_handler; |
| 57 Timer timer; |
| 58 Context app_context; |
| 59 app_context.graphics_handler = &graphics_handler; |
| 60 app_context.input_handler = &input_handler; |
| 61 app_context.sound_handler = &sound_handler; |
| 62 app_context.timer = &timer; |
| 63 app_context.vm_glue = &vm_glue; |
| 64 DartHost host(&app_context); |
| 65 lifecycle_handler_ptr = &host; |
| 66 lifecycle_handler_ptr->OnActivate(); |
| 67 glutReshapeFunc(reshape); |
| 68 glutDisplayFunc(display); |
| 69 glutKeyboardFunc(keyboard); |
| 70 glutIdleFunc(display); |
| 71 glutMainLoop(); |
| 72 } |
| 73 |
OLD | NEW |