spBase
読み取り中…
検索中…
一致する文字列を見つけられません
spMain.h
[詳解]
1
4#ifndef __SPMAIN_H
5#define __SPMAIN_H
6
7#if defined(__cplusplus) && !defined(SP_DISABLE_ABBREVIATION)
8#define SP_DISABLE_ABBREVIATION 1
9#define SP_ENABLE_ABBREVIATION_LATER 1
10#endif
11
12#include <sp/spBase.h>
13
14#if defined(SP_ENABLE_ABBREVIATION_LATER)
15#undef SP_DISABLE_ABBREVIATION
16#undef SP_ENABLE_ABBREVIATION_LATER
17#endif
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#if defined(MACOS)
24
25#pragma import on
26int spMain(int argc, char *argv[]);
27#pragma import off
28
29int main(int argc, char *argv[])
30{
31#if !(defined(MACOSX64) || defined(IPHONE)) && !TARGET_API_MAC_CARBON
32 MaxApplZone();
33#endif
34 return spMain(argc, argv);
35}
36
37#elif defined(ANDROID)
38#include <jni.h>
39#include <android_native_app_glue.h>
40#include <android/log.h>
41
42#define SP_LOG_TAG "spMain.h"
43#define SP_LOGI(...) __android_log_print(ANDROID_LOG_INFO,SP_LOG_TAG,__VA_ARGS__)
44
45extern void spUpdateDirectoryAndroid(JNIEnv *env, jobject clazzobj);
46
47int spMain(int argc, char *argv[]);
48
49static void spEngineHandleCmd(struct android_app* app, int32_t cmd) {
50}
51
52static int32_t spEngineHandleInput(struct android_app* app, AInputEvent* event) {
53 if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) {
54 SP_LOGI("Key event: action=%d keyCode=%d metaState=0x%x",
55 AKeyEvent_getAction(event),
56 AKeyEvent_getKeyCode(event),
57 AKeyEvent_getMetaState(event));
58 } else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
59 SP_LOGI("Motion event: (%f, %f)",
60 AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0));
61 }
62 return 0;
63}
64
65void android_main(struct android_app* state) {
66 int ident;
67 int events;
68 JavaVM *vm;
69 JNIEnv *env;
70 struct android_poll_source* source;
71 char *argv[1] = {"main"};
72
73 /*app_dummy();*/
74 state->onAppCmd = spEngineHandleCmd;
75 state->onInputEvent = spEngineHandleInput;
76
77 vm = state->activity->vm;
78 (*vm)->AttachCurrentThread(vm, &env, NULL);
79 spUpdateDirectoryAndroid(env, state->activity->clazz);
80 (*vm)->DetachCurrentThread(vm);
81
82 spMain(1, argv);
83
84 while ((ident = ALooper_pollAll(-1, NULL, &events, (void**)&source)) >= 0) {
85 // Process this event.
86 if (source != NULL) {
87 source->process(state, source);
88 }
89
90 // Check if we are exiting.
91 if (state->destroyRequested != 0) {
92 SP_LOGI("Engine thread destroy requested!");
93 return;
94 }
95 }
96}
97#elif defined(_WIN32) && !defined(__CYGWIN32__)
98int spMain(int argc, char *argv[]);
99
100int main(int argc, char *argv[])
101{
102#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
103 _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
104#endif
105 spsetstdio(stdin, stdout, stderr);
106 return spMain(argc, argv);
107}
108#else
109#define spMain main
110#endif
111
112#ifdef __cplusplus
113} /* Close scope of 'extern "C"' declaration */
114#endif
115
116#endif /* __SPMAIN_H */