Skip to content

Commit

Permalink
Merged in master (pull request #2)
Browse files Browse the repository at this point in the history
Add native Haiku UI

Approved-by: Andrey Dj
  • Loading branch information
threedeyes authored and djdron committed Jan 17, 2024
2 parents a60a230 + a48fff7 commit 87ac0c5
Show file tree
Hide file tree
Showing 30 changed files with 5,008 additions and 4 deletions.
41 changes: 38 additions & 3 deletions build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
option(USE_WX_WIDGETS "wxWidgets + OpenAL + OpenGL version" OFF)
option(USE_SDL "SDL version" ON)
option(USE_SDL2 "SDL2 version" OFF)
option(USE_HAIKU "Haiku version" OFF)
option(USE_BENCHMARK "benchmark mode (console)" OFF)
option(USE_LIBRARY "library mode" OFF)
option(USE_WEB "use web sources (SDL or iOS versions)" ON)
Expand Down Expand Up @@ -60,7 +61,7 @@ source_group("devices\\sound" FILES ${SRCCXX_DEVICES_SOUND} ${SRCH_DEVICES_SOUND

#3rdparty libs

if(NOT APPLE_IOS AND NOT ANDROID AND (USE_SDL OR USE_SDL2) AND USE_WEB AND NOT EMSCRIPTEN)
if(NOT APPLE_IOS AND NOT ANDROID AND (USE_SDL OR USE_SDL2 OR USE_HAIKU) AND USE_WEB AND NOT EMSCRIPTEN)
find_package(CURL REQUIRED)
if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
Expand Down Expand Up @@ -144,7 +145,7 @@ source_group("platform\\oal" FILES ${SRCCXX_PLATFORM_OPENAL})

endif(USE_WX_WIDGETS OR APPLE_IOS)

if(NOT ANDROID AND (USE_SDL OR USE_SDL2 OR APPLE_IOS))
if(NOT ANDROID AND (USE_SDL OR USE_SDL2 OR APPLE_IOS OR USE_HAIKU))

file(GLOB SRCCXX_UI "../../ui/*.cpp")
file(GLOB SRCH_UI "../../ui/*.h")
Expand All @@ -169,7 +170,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif(NOT MSVC)
endif(USE_WEB)

endif(NOT ANDROID AND (USE_SDL OR USE_SDL2 OR APPLE_IOS))
endif(NOT ANDROID AND (USE_SDL OR USE_SDL2 OR APPLE_IOS OR USE_HAIKU))

if(USE_SDL2 OR APPLE_IOS OR ANDROID)

Expand Down Expand Up @@ -359,6 +360,22 @@ add_executable(${PROJECT} WIN32 ${SRCCXX} ${SRCC} ${SRCH} ${SRCRES})
target_link_libraries(${PROJECT} wx::core wx::base wx::adv wx::aui wx::gl)
target_link_libraries(${PROJECT} ${OPENGL_LIBRARIES})

elseif(USE_HAIKU)

#Haiku
file(GLOB SRCCXX_PLATFORM_HAIKU "../../platform/haiku/*.cpp")
add_definitions(-DAPP_SIGNATURE="application/x-vnd.unreal-speccy-portable" -DUSE_HAIKU -DUSE_PNG -DUSE_UI -DUSE_CONFIG -DUSE_ZIP)
if(USE_WEB)
add_definitions(-DUSE_WEB)
endif(USE_WEB)
list(APPEND SRCCXX ${SRCCXX_PLATFORM_HAIKU})
source_group("platform\\haiku" FILES ${SRCCXX_PLATFORM_HAIKU})

add_platform_io_stuff()

add_executable(${PROJECT} WIN32 ${SRCCXX} ${SRCC} ${SRCH})
target_link_libraries(${PROJECT} -lbe -lmedia -ldevice -lgame -ltracker -llocalestub -lpng)

elseif(USE_SDL)

#SDL
Expand Down Expand Up @@ -540,6 +557,24 @@ endif(APPLE_IOS)

target_link_libraries(${PROJECT} ${THIRDPARTY_LIBRARIES})

if(HAIKU)
add_custom_target(Resources ALL
DEPENDS ${PROJECT}
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../../platform/haiku/resources.rdef)
add_custom_command(TARGET Resources
COMMAND rc -o resources.rsrc ${CMAKE_CURRENT_SOURCE_DIR}/../../platform/haiku/resources.rdef
COMMENT "${P} Compiling resource file."
VERBATIM)
add_custom_command(TARGET Resources
COMMAND xres -o ${PROJECT} resources.rsrc
COMMENT "${P} Adding compiled resources to '${PROJECT}' executable."
VERBATIM)
add_custom_command(TARGET Resources
COMMAND mimeset --all ${PROJECT}
COMMENT "${P} Updating MIME types for '${PROJECT}' executable."
VERBATIM)
endif(HAIKU)

if(MSVC AND NOT UWP)
set_target_properties(${PROJECT} PROPERTIES LINK_FLAGS "/MANIFEST:NO /LARGEADDRESSAWARE")
endif(MSVC AND NOT UWP)
Expand Down
139 changes: 139 additions & 0 deletions platform/haiku/haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
Portable ZX-Spectrum emulator.
Copyright (C) 2001-2021 SMT, Dexus, Alone Coder, deathsoft, djdron, scor, 3dEyes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "../platform.h"
#include "../../options_common.h"
#include "../../tools/tick.h"
#include "../io.h"

#include <AppKit.h>
#include <StorageKit.h>
#include <FindDirectory.h>

#include "haiku_app.h"

namespace xPlatform
{

void InitAudio();
void DoneAudio();
void UpdateAudio();

bool InitVideo();
void DoneVideo();
void UpdateScreen();

bool InitJoystick();
void DoneJoystick();
void ProcessJoystick();

static int32 appThreadFunc(void *data)
{
USPApplication *application = new USPApplication(APP_SIGNATURE);

app_info theInfo;
application->GetAppInfo(&theInfo);
BPath appPath(&theInfo.ref);
BPath dirPath;
appPath.GetParent(&dirPath);
chdir(dirPath.Path());

application->Run();

return 0;
}

static bool Init()
{
thread_id appThreadId = spawn_thread(appThreadFunc, "USPApplication", B_NORMAL_PRIORITY, NULL);
resume_thread(appThreadId);

while(true) {
if (be_app) {
if (!be_app->IsLaunching())
break;
}
snooze(1000);
}

BPath settings_path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &settings_path) == B_OK) {
settings_path.Append("USP");
BString usp_home_path(settings_path.Path());
usp_home_path += "/";
xIo::PathCreate(usp_home_path.String());
xIo::SetProfilePath(usp_home_path.String());
OpLastFile(usp_home_path.String());
}

Handler()->OnInit();

InitJoystick();
InitAudio();
InitVideo();

return true;
}

static void Done()
{
DoneJoystick();
DoneAudio();
DoneVideo();

Handler()->OnDone();
}

static bool quit = false;

void Loop()
{
eTick last_tick;
last_tick.SetCurrent();
while(!quit) {
Handler()->OnLoop();
UpdateScreen();
ProcessJoystick();
UpdateAudio();

while(last_tick.Passed().Ms() < 15)
snooze(3000);

last_tick.SetCurrent();
if(OpQuit())
quit = true;
}
}

}

int main(int argc, char* argv[])
{
if(!xPlatform::Init()) {
xPlatform::Done();
return -1;
}

if(argc > 1)
xPlatform::Handler()->OnOpenFile(argv[1]);

xPlatform::Loop();
xPlatform::Done();

return 0;
}
47 changes: 47 additions & 0 deletions platform/haiku/haiku_app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Portable ZX-Spectrum emulator.
Copyright (C) 2001-2021 SMT, Dexus, Alone Coder, deathsoft, djdron, scor, 3dEyes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "../platform.h"
#include "../../tools/options.h"
#include "../../options_common.h"

#include "haiku_app.h"
#include "haiku_window.h"

namespace xPlatform
{

USPApplication::USPApplication(const char *signature) : BApplication(signature),
refsReceived(NULL)
{
}

void
USPApplication::RefsReceived(BMessage* message)
{
refsReceived = new BMessage(*message);
for (int i = 0; i < CountWindows(); i++) {
HaikuPlatformWindow *window = dynamic_cast <HaikuPlatformWindow*>(WindowAt(i));
if (window) {
window->PostMessage(refsReceived);
break;
}
}
}

}
40 changes: 40 additions & 0 deletions platform/haiku/haiku_app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Portable ZX-Spectrum emulator.
Copyright (C) 2001-2021 SMT, Dexus, Alone Coder, deathsoft, djdron, scor, 3dEyes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _HAIKU_APPLICATION_H
#define _HAIKU_APPLICATION_H

#include <Application.h>
#include <Message.h>

namespace xPlatform
{

class USPApplication : public BApplication {
public:
USPApplication(const char *signature);
virtual void RefsReceived(BMessage* message);

BMessage* GetRefsMessage() { return refsReceived; }
private:
BMessage* refsReceived;
};

}

#endif
Loading

0 comments on commit 87ac0c5

Please sign in to comment.