Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add os time support and small fixes for vpk export #50

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions platform/vita/export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class EditorExportPlatformVita : public EditorExportPlatform {
sfo->parental_level = p_preset->get("param_sfo/parental_level");

String icon = p_preset->get("assets/bubble_icon_128x128");
String splash = p_preset->get("assets/launch_splash_960x544");
String splash = p_preset->get("assets/app_splash_960x544");
String livearea_bg = p_preset->get("assets/livearea_bg_840x500");
String livearea_startup_button = p_preset->get("assets/livearea_startup_button_280x158");

Expand Down Expand Up @@ -324,7 +324,7 @@ class EditorExportPlatformVita : public EditorExportPlatform {
}
}

create_vpk(sfo->title + ".vpk", app_dir);
create_vpk(base_path + ".vpk", app_dir);
memdelete(sfo);
memdelete(da);
da = nullptr;
Expand Down
65 changes: 62 additions & 3 deletions platform/vita/os_vita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ void OS_Vita::key(uint32_t p_key, bool p_pressed) {
ev->set_scancode(p_key);
ev->set_unicode(p_key);
input->parse_input_event(ev);
}

bool OS_Vita::has_touchscreen_ui_hint() const {
return true;
};

bool OS_Vita::has_virtual_keyboard() const {
Expand Down Expand Up @@ -603,15 +607,70 @@ bool OS_Vita::set_environment(const String &p_var, const String &p_value) const
}

OS::Date OS_Vita::get_date(bool local) const {
return OS::Date();
SceDateTime sceDateTime;
if (local)
sceRtcGetCurrentClockUtc(&sceDateTime);
else
sceRtcGetCurrentClockLocalTime(&sceDateTime);
// TODO: Daylight calculation.
bool daylight = false;
Date date;
date.day = sceDateTime.day;
date.month = Month(sceDateTime.month);
date.year = sceDateTime.year;
date.weekday = Weekday(sceRtcGetDayOfWeek(sceDateTime.year, sceDateTime.month, sceDateTime.day));
date.dst = daylight;
return date;
}

OS::Time OS_Vita::get_time(bool local) const {
return OS::Time();
SceDateTime sceDateTime;
if (local)
sceRtcGetCurrentClockUtc(&sceDateTime);
else
sceRtcGetCurrentClockLocalTime(&sceDateTime);
Time time;
time.hour = sceDateTime.hour;
time.min = sceDateTime.minute;
time.sec = sceDateTime.second;
return time;
}

OS::TimeZoneInfo OS_Vita::get_time_zone_info() const {
return OS::TimeZoneInfo();
OS::TimeZoneInfo timeZoneInfo;
SceDateTime sceDateTimeUtc;
SceDateTime sceDateTimeLocal;
sceRtcGetCurrentClockUtc(&sceDateTimeUtc);
sceRtcGetCurrentClockLocalTime(&sceDateTimeLocal);
int hourBias = sceDateTimeLocal.hour - sceDateTimeUtc.hour;
if (hourBias < 0) {
hourBias += 24;
}
String sign = (hourBias >= 0) ? "+" : "-";
int local_offset = (hourBias > 0 ? hourBias : -hourBias);
String offset = (local_offset < 10) ? "0" + String::num_int64(local_offset) : String::num_int64(local_offset);
timeZoneInfo.name = "UTC" + sign + offset;
timeZoneInfo.bias = hourBias * 60;
return timeZoneInfo;
}

uint64_t OS_Vita::get_unix_time() const {
uint64_t unixTime;
SceDateTime sceDateTimeUtc;
sceRtcGetCurrentClockUtc(&sceDateTimeUtc);
sceRtcConvertDateTimeToTime64_t(&sceDateTimeUtc, &unixTime);
return unixTime;
}

uint64_t OS_Vita::get_system_time_secs() const {
return get_system_time_msecs() / 1000L;
}

uint64_t OS_Vita::get_system_time_msecs() const {
struct timespec tv_now = { 0, 0 };
clock_gettime(CLOCK_MONOTONIC, &tv_now);
uint64_t longtime = ((uint64_t)tv_now.tv_nsec / 1000000L) + (uint64_t)tv_now.tv_sec * 1000L;
return longtime;
}

void OS_Vita::delay_usec(uint32_t p_usec) const {
Expand Down
4 changes: 4 additions & 0 deletions platform/vita/os_vita.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class OS_Vita : public OS {
virtual bool can_draw() const;

void key(uint32_t p_key, bool p_pressed);
virtual bool has_touchscreen_ui_hint() const;
virtual bool has_virtual_keyboard() const;
virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), bool p_multiline = false, int p_max_input_length = -1, int p_cursor_start = -1, int p_cursor_end = -1);
virtual void hide_virtual_keyboard();
Expand Down Expand Up @@ -155,6 +156,9 @@ class OS_Vita : public OS {
virtual Date get_date(bool local = false) const;
virtual Time get_time(bool local = false) const;
virtual TimeZoneInfo get_time_zone_info() const;
virtual uint64_t get_unix_time() const;
virtual uint64_t get_system_time_secs() const;
virtual uint64_t get_system_time_msecs() const;
virtual void delay_usec(uint32_t p_usec) const;
virtual uint64_t get_ticks_usec() const;
virtual String get_stdin_string();
Expand Down
Loading