Skip to content

Commit

Permalink
Android:
Browse files Browse the repository at this point in the history
-Fixed android.mk to support the newest Android Studio;
-Added Basic documentation about how to create a MT2D Android Studio Project.
-Fixed many include files for ANDROID.
-Fixed a strange bug where SDL_SOUND_TYPE failed to compare with -1 so the Audio system wouldn't start.
  • Loading branch information
lucas-zimerman committed Aug 25, 2018
1 parent 6ff9c56 commit 1a6be42
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 29 deletions.
10 changes: 5 additions & 5 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ include $(CLEAR_VARS)

LOCAL_MODULE := MT2D

SDL_PATH := ../SDL2
SDL_PATH := ../SDL
SDL_IMAGE_PATH := ../SDL2_image
SDL_MIXER_PATH := ../SDL2_mixer



LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include \ $(LOCAL_PATH)/$(SDL_MIXER_PATH)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include \ $(LOCAL_PATH)/$(SDL_MIXER_PATH) \ $(LOCAL_PATH)/$(SDL_IMAGE_PATH)

LOCAL_SRC_FILES := \
$(subst $(LOCAL_PATH)/,, \
$(wildcard $(LOCAL_PATH)/MT2D/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/Audio/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/Container/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/Cursor/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/InputBox/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/Joystick/*.cpp) \
Expand All @@ -26,13 +28,11 @@ LOCAL_SRC_FILES := \
$(wildcard $(LOCAL_PATH)/MT2D/SDL/Render/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/Tools/UserInterface/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/_ANDROID/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/_ANDROID/IO/*.cpp) \
$(wildcard $(LOCAL_PATH)/MT2D/Tools/Video/*.cpp))

LOCAL_LDLIBS :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES := SDL2 SDL2_mixer SDL2_image


LOCAL_EXPORT_C_INCLUDES += $(LOCAL_C_INCLUDES)

include $(BUILD_SHARED_LIBRARY)
83 changes: 83 additions & 0 deletions Documentation/Use Android Studio.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
This is a simple tutorial teaching you how to set up MT2D on Android Studio
-You'll probably face problens trying to compile it, but mostly the iuses are going to be
-"easy" to solve (if you know NDK and Android studio)

REQUIRED:
SDL2 source: https://www.libsdl.org/download-2.0.php
SDL2_Image source: https://www.libsdl.org/projects/SDL_image/
SDL2_Mixer source: https://www.libsdl.org/projects/SDL_mixer/
MT2D source:

Clone android-project

on gradle->wrapper->gradle-wrapper.properties

-edit the distributionUrl to (or leave if the gradle version on it is higher than 4.1) distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

go to File -> Project Structure.
1)on the App Module
2)Set Source and Target compatibility to the highest number.

Create symbolic links, open cmd as administrator.
1)go to your project folder
2)go to the app->jni folder.
2.2 for maki making a symbolic link you do the following command:
2.3 mklink /D *link name* *real folder*
2.4 example: mklink /D SDL2 C:\Libs\SDL2
<!> DONT USE SPACES IN THE FOLDER NAME
3)created a symbolic link named SDL (NOT SDL2!)
4)create a symbolic link called SDL2_MIXER
5)create a symbolic link called SDL2_IMAGE
6)create a symbolic link called MT2D

on app->jni->src->Android.mk add the below code between the #### below the SDL_PATH

####
SDL_MIXER_PATH := ../SDL2_mixer
SDL_IMAGE_PATH := ../SDL2_image
MT2D_PATH := ../MT2D
####

on the same file, edit the LOCAL_C_INCLUDES to

####
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(SDL_MIXER_PATH) \
$(LOCAL_PATH)/$(SDL_IMAGE_PATH) \
$(LOCAL_PATH)/$(MT2D_PATH)
####

on the same file edit the LOCAL_SHARED_LIBRARIES to
####
LOCAL_SHARED_LIBRARIES := SDL2 SDL2_mixer SDL2_image MT2D
####

on app->jni->Application.mk, remobe the # from the APP_STL := stlport_static

for testing if everythign is working, make a simple main code like

#####
#include <SDL.h>
#include <MT2D/MT2D.h>
#include <MT2D/MT2D_Display.h>
#include <MT2D/Audio/MT2D_Audio_core.h>
#include <MT2D/MessageBox\MT2D_MessageBox.h>


#define APPNAME "Project-MT2D"

int main(int argc, char *argv[])
{
MT2D_Init();
MT2D_Audio_Init();
// MT2D_Play_Music("menu.ogg");
MT2D_Clear_Main_Window();
MT2D_MessageBox("Yeah boy, its working on android!");
return 0;
}
#####

NOTES:
-All files that are going to be used by your app must be inside the Assets folder.
-his folder must be created inside the main folder, ie.
-app->src->main
2 changes: 1 addition & 1 deletion MT2D/Audio/MT2D_Audio_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "../SDL/Audio/MT2D_SDL_Audio.h"
#define MT2D_Play_Audio SDL_Play_Sound
#define MT2D_Play_Music SDL_Play_Music
#define MT2D_Audio_Init SDL_Start_Sound_System
#define MT2D_Audio_Init() SDL_Start_Sound_System()
#define MT2D_Audio_Close SDL_Close_Sound_System
#else
#ifndef MT2D_AUIDO_WARN
Expand Down
4 changes: 4 additions & 0 deletions MT2D/Cursor/Cursor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if ! defined(SDL_USE) || !defined(WINDOWS_TARGET) || !defined(__MSDOS__) || !defined(linux)
void MT2D_Cursor_goto_topscreen() {}
void MT2D_Cursor_Set_Position(int line, int column) {}
#endif
8 changes: 6 additions & 2 deletions MT2D/Cursor/Cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#endif

#if defined(SDL_USE)
#define MT2D_Cursor_goto_topscreen 0
#define MT2D_Cursor_Set_Position 0
#define MT2D_Cursor_goto_topscreen
#define MT2D_Cursor_Set_Position
#elif defined(WINDOWS_TARGET)
#include "..\_WINDOWS\MT2D_Win_Cursor.h"
#define MT2D_Cursor_goto_topscreen MT2D_Win_Cursor_goto_topscreen
Expand All @@ -26,6 +26,10 @@
#include "../_LINUX/MT2D_Linux_Cursor.h"
#define MT2D_Cursor_goto_topscreen MT2D_Linux_Cursor_goto_topscreen
#define MT2D_Cursor_Set_Position MT2D_Linux_Cursor_Set_Position
#elif defined(__ANDROID__)
#include "../_ANDROID/MT2D_Droid_Cursor.h"
#define MT2D_Cursor_goto_topscreen MT2D_Droid_Cursor_goto_topscreen
#define MT2D_Cursor_Set_Position MT2D_Droid_Cursor_Set_Position
#else
void MT2D_Cursor_goto_topscreen();
void MT2D_Cursor_Set_Position(int line, int column);
Expand Down
5 changes: 5 additions & 0 deletions MT2D/Joystick/MT2D_Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ typedef struct{
#define MT2D_Joystick_Init MT2D_Dos_Joystick_Init
#define MT2D_Joystick_Close MT2D_Dos_Joystick_Close
#define MT2D_Joystick_Update MT2D_Dos_Joystick_Update
#elif defined(__ANDROID__)
#include "../_ANDROID/IO/MT2D_Droid_Joystick.h"
#define MT2D_Joystick_Init MT2D_Droid_Joystick_Init
#define MT2D_Joystick_Close MT2D_Droid_Joystick_Close
#define MT2D_Joystick_Update MT2D_Droid_Joystick_Update
#else
#error "No code was done for this platform"
#endif
Expand Down
4 changes: 4 additions & 0 deletions MT2D/MT2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include <stdio.h>

void quack(){

}
#if !defined(__MSDOS__) && !defined(__ANDROID__)
#include "MT2D/MT2D_Terminal_Define.h"
#elif defined(__ANDROID__)
Expand Down Expand Up @@ -41,6 +44,7 @@
unsigned char WINDOW1[MAX_VER + 1][MAX_HOR];
unsigned char WINDOW2[MAX_VER + 1][MAX_HOR];


/*
bool MT2D_Deprecated_Init() {// Return: true - it started without any kind of problem, false : there were a problem when MT2D was started
bool output = true;
Expand Down
6 changes: 4 additions & 2 deletions MT2D/MT2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ linker settings: (In case of codeblocks: project -> build options -> linker sett
#include <SDL.h>
#endif
#endif

//#include <stdbool.h>
#ifndef bool
#include <stdbool.h>
#endif

#define DISPLAY_WINDOW1 1
#define DISPLAY_WINDOW2 0
Expand Down Expand Up @@ -119,3 +120,4 @@ void insert_number_on_display(int number, int pos_y,int pos_x, bool display);
#endif

#endif
void quack();
2 changes: 1 addition & 1 deletion MT2D/MessageBox/MT2D_MessageBox_With_Result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int MT2D_MessageBox_With_Result(char *error_mensage_title,char *error_mensage, c
WINDOW2[13][35]='(';WINDOW2[13][36]='2';WINDOW2[13][37]=')';
i=0;
MT2D_Draw_Window(DISPLAY_WINDOW2);
MT2D_Cursor_goto_topscreen();
MT2D_Cursor_goto_topscreen;
while(i!='1' && i!='2'){
i=MT2D_Keyboard_keytouched();
if(i==224)
Expand Down
17 changes: 9 additions & 8 deletions MT2D/ObjectCore/Sprites.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <MT2D/Objectcore/Coordinates.h>
#include <MT2D/MT2D_Terminal_Define.h>
#else
#include "../Objectcore/Coordinates.h"
#warning "#include \../Objectcore/Coordinates.h\ testar se funciona melhor agora"
#include "Coordinates.h"
#include "../MT2D_Terminal_Define.h"
#endif

Expand All @@ -13,26 +14,26 @@ struct Sprite {
#ifdef SDL_USE
char **RotatedTexture;
#endif
Coord size;//The size of the sprite
Coord scale;//the scale of the image applied to a 320x240 screen
struct Coord size;//The size of the sprite
struct Coord scale;//the scale of the image applied to a 320x240 screen
char type;/* ASCII image = 0, Image = 1*/
};

/**
Loads an ASCII OEM850 formated text file
**/
Sprite *Load_Sprite(char *file);
struct Sprite *Load_Sprite(char *file);

/**
Loads an image
**/
Sprite *Load_Sprite_Image(char *file,int ScaleX,int ScaleY);
struct Sprite *Load_Sprite_Image(char *file,int ScaleX,int ScaleY);
#if defined(MT2D_USING_CONTAINER)
Sprite *Load_Sprite_Image_From_Container(char *file, int ScaleX, int ScaleY);
struct Sprite *Load_Sprite_Image_From_Container(char *file, int ScaleX, int ScaleY);
#else
#define Load_Sprite_Image_From_Container null
khk
#endif
bool Sprite_Render_on_Window(Sprite *img, int witch_window, int pos_x, int pos_y);
void Sprite_Delete(Sprite *Me);
bool Sprite_Render_on_Window(struct Sprite *img, int witch_window, int pos_x, int pos_y);
void Sprite_Delete(struct Sprite *Me);
#endif
3 changes: 1 addition & 2 deletions MT2D/SDL/Audio/MT2D_SDL_Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ void SDL_Start_Sound_System()
SDL_ABuffer.SDL_AUDIO_STARTED = 0;
SDL_ABuffer.SDL_music = 0;
SDL_ABuffer.sound_loaded = 0;

if(SDL_SOUND_TYPE == -1){
if(SDL_SOUND_TYPE == (char)-1){
SDL_SOUND_TYPE = 1;
if(SDL_Init(SDL_INIT_AUDIO) < 0){
exit(1);
Expand Down
9 changes: 5 additions & 4 deletions MT2D/SDL/MT2D_SDL_main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifdef __MSDOS__
/*#ifdef __MSDOS__
#include "../../MT2D/MT2D_Terminal_Define.h"
#else
#include "../MT2D_Terminal_Define.h"
#endif
#ifdef SDL_USE
*/
#include "MT2D_SDL_Defines.h"
#include <MT2D/SDL/MT2D_SDL_Redefine.h>
#include "MT2D_SDL_Event_Handler.h"
Expand Down Expand Up @@ -470,7 +471,7 @@ void close()
SDL_Quit();
}

#else
#pragma message("MT2D_SDL_main:You must define SDL_USE to use the SDL code")
#endif
//#else
//#pragma message("MT2D_SDL_main:You must define SDL_USE to use the SDL code")
//#endif

6 changes: 3 additions & 3 deletions MT2D/SDL/MT2D_SDL_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ SDL_MT2Dmain.h SDL_MT2Dmain.cpp created by: Lucas Zimerman Fraulob
https://www.libsdl.org/
https://wiki.libsdl.org/
===================================================================*/
#include "../MT2D_Terminal_Define.h"
#if !defined(_MT2D_SDL_MAIN_H) && defined(SDL_USE)
//#include "../MT2D_Terminal_Define.h"
//#if !defined(_MT2D_SDL_MAIN_H) && defined(SDL_USE)
#define _MT2D_SDL_MAIN_H
#include <MT2D/SDL/MT2D_SDL_Redefine.h>

Expand All @@ -48,4 +48,4 @@ SDL_MT2Dmain.h SDL_MT2Dmain.cpp created by: Lucas Zimerman Fraulob
MT2D_SDL_Texture *MT2D_SDL_Create_Rotated_Texture(SDL_Surface *Surface, MT2D_SDL_Texture *newTexture);


#endif
//#endif
2 changes: 1 addition & 1 deletion MT2D/SDL/Render/MT2D_SDL_Render.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void Clean_Render();
void Render_New(unsigned char BUFFER[][MAX_HOR]);
void SDL_Render();

void SDL_Add_ImagetoBuffer(Sprite *IMG, int X, int Y);
void SDL_Add_ImagetoBuffer(struct Sprite *IMG, int X, int Y);
void SDL_Clear_RenderBuffers();

/**/
Expand Down
46 changes: 46 additions & 0 deletions MT2D/_ANDROID/IO/MT2D_Droid_Joystick.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*code can be used with SDL*/
#ifdef __ANDROID__
#include "../../MT2D_Terminal_Define.h"

#include "../../Joystick/MT2D_Joystick.h"
#include "../../MT2D_Debug.h"

#include <cstdlib>
#include <cstdio>

extern MT2D_Joystick *GlobalJoystickHandler;


void MT2D_Dos_Joystick_Init() {
GlobalJoystickHandler = (MT2D_Joystick*)malloc(sizeof(MT2D_Joystick));
GlobalJoystickHandler->Button_Pressed[0] = false;
GlobalJoystickHandler->Button_Pressed[1] = false;
GlobalJoystickHandler->Button_Pressed[2] = false;
GlobalJoystickHandler->Button_Pressed[3] = false;
GlobalJoystickHandler->Left_Modified = false;
GlobalJoystickHandler->Left_X_axis = 0;
GlobalJoystickHandler->Left_Y_axis = 0;
GlobalJoystickHandler->Right_Modified = false;
GlobalJoystickHandler->Right_X_axis = 0;
GlobalJoystickHandler->Right_Y_axis = 0;
GlobalJoystickHandler->Touched = false;
GlobalJoystickHandler->DeadZoneAxis = 8000;
}
void MT2D_Dos_Joystick_Close() {
free(GlobalJoystickHandler);
}

void MT2D_Dos_Joystick_Update() {
int Key = 0;
int hardcoredebug = 0;
//clear the joystick buffer.
GlobalJoystickHandler->Button_Pressed[0] = false;
GlobalJoystickHandler->Button_Pressed[1] = false;
GlobalJoystickHandler->Button_Pressed[2] = false;
GlobalJoystickHandler->Button_Pressed[3] = false;
GlobalJoystickHandler->Right_Modified = false;
GlobalJoystickHandler->Right_X_axis = 0;
GlobalJoystickHandler->Right_Y_axis = 0;
}

#endif
6 changes: 6 additions & 0 deletions MT2D/_ANDROID/IO/MT2D_Droid_Joystick.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#if defined(__ANDROID__) && !defined(MTDOS_JOY_H)
#define MTDOS_JOY_H
void MT2D_Droid_Joystick_Init();
void MT2D_Droid_Joystick_Close();
void MT2D_Droid_Joystick_Update();
#endif
10 changes: 10 additions & 0 deletions MT2D/_ANDROID/MT2D_Droid_Cursor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "../MT2D_Terminal_Define.h"

#if defined(__ANDROID__)

void MT2D_Droid_Cursor_goto_topscreen() {
}

void MT2D_Droid_Cursor_Set_Position(int line, int column) {
}
#endif
Loading

0 comments on commit 1a6be42

Please sign in to comment.