Skip to content

Commit

Permalink
-Changed bootsplash option to use a file, fixes godotengine#1539
Browse files Browse the repository at this point in the history
-Added OS.get_splash_tick_msec() to query when splash appeared
  • Loading branch information
reduz committed Apr 12, 2015
1 parent 2dfa127 commit 3e20391
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 10 deletions.
5 changes: 5 additions & 0 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ uint32_t _OS::get_ticks_msec() const {
return OS::get_singleton()->get_ticks_msec();
}

uint32_t _OS::get_splash_tick_msec() const {

return OS::get_singleton()->get_splash_tick_msec();
}

bool _OS::can_use_threads() const {

Expand Down Expand Up @@ -765,6 +769,7 @@ void _OS::_bind_methods() {
ObjectTypeDB::bind_method(_MD("delay_usec","usec"),&_OS::delay_usec);
ObjectTypeDB::bind_method(_MD("delay_msec","msec"),&_OS::delay_msec);
ObjectTypeDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec);
ObjectTypeDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec);
ObjectTypeDB::bind_method(_MD("get_locale"),&_OS::get_locale);
ObjectTypeDB::bind_method(_MD("get_model_name"),&_OS::get_model_name);

Expand Down
1 change: 1 addition & 0 deletions core/bind/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class _OS : public Object {
void delay_usec(uint32_t p_usec) const;
void delay_msec(uint32_t p_msec) const;
uint32_t get_ticks_msec() const;
uint32_t get_splash_tick_msec() const;

bool can_use_threads() const;

Expand Down
3 changes: 3 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ OS* OS::get_singleton() {
uint32_t OS::get_ticks_msec() const
{ return get_ticks_usec()/1000; }

uint64_t OS::get_splash_tick_msec() const {
return _msec_splash;
}
uint64_t OS::get_unix_time() const {

return 0;
Expand Down
4 changes: 4 additions & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class OS {
String _local_clipboard;
uint64_t frames_drawn;
uint32_t _frame_delay;
uint64_t _msec_splash;
bool _no_window;
int _exit_code;
int _orientation;
Expand Down Expand Up @@ -251,6 +252,7 @@ friend class Main;
virtual void delay_usec(uint32_t p_usec) const=0;
virtual uint64_t get_ticks_usec() const=0;
uint32_t get_ticks_msec() const;
uint64_t get_splash_tick_msec() const;

void set_frame_delay(uint32_t p_msec);
uint32_t get_frame_delay() const;
Expand Down Expand Up @@ -384,6 +386,8 @@ friend class Main;
void set_time_scale(float p_scale);
float get_time_scale() const;



OS();
virtual ~OS();

Expand Down
16 changes: 13 additions & 3 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,23 @@ Error Main::setup2() {
#endif

if (show_logo) { //boot logo!
Image boot_logo=GLOBAL_DEF("application/boot_logo",Image());
String boot_logo_path=GLOBAL_DEF("application/boot_splash",String());
bool boot_logo_scale=GLOBAL_DEF("application/boot_splash_fullsize",true);
Globals::get_singleton()->set_custom_property_info("application/boot_splash",PropertyInfo(Variant::STRING,"application/boot_splash",PROPERTY_HINT_FILE,"*.png"));


Image boot_logo;

if (boot_logo_path.strip_edges()!="" && FileAccess::exists(boot_logo_path)) {
boot_logo.load(boot_logo_path);
}

if (!boot_logo.empty()) {
OS::get_singleton()->_msec_splash=OS::get_singleton()->get_ticks_msec();
Color clear = GLOBAL_DEF("render/default_clear_color",Color(0.3,0.3,0.3));
VisualServer::get_singleton()->set_default_clear_color(clear);
Color boot_bg = GLOBAL_DEF("application/boot_bg_color", clear);
VisualServer::get_singleton()->set_boot_image(boot_logo, boot_bg);
VisualServer::get_singleton()->set_boot_image(boot_logo, boot_bg,boot_logo_scale);
#ifndef TOOLS_ENABLED
//no tools, so free the boot logo (no longer needed)
Globals::get_singleton()->set("application/boot_logo",Image());
Expand All @@ -788,7 +798,7 @@ Error Main::setup2() {
MAIN_PRINT("Main: ClearColor");
VisualServer::get_singleton()->set_default_clear_color(boot_splash_bg_color);
MAIN_PRINT("Main: Image");
VisualServer::get_singleton()->set_boot_image(splash, boot_splash_bg_color);
VisualServer::get_singleton()->set_boot_image(splash, boot_splash_bg_color,false);
#endif
MAIN_PRINT("Main: DCC");
VisualServer::get_singleton()->set_default_clear_color(GLOBAL_DEF("render/default_clear_color",Color(0.3,0.3,0.3)));
Expand Down
26 changes: 22 additions & 4 deletions servers/visual/visual_server_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7391,7 +7391,7 @@ void VisualServerRaster::set_default_clear_color(const Color& p_color) {
clear_color=p_color;
}

void VisualServerRaster::set_boot_image(const Image& p_image, const Color& p_color) {
void VisualServerRaster::set_boot_image(const Image& p_image, const Color& p_color,bool p_scale) {

if (p_image.empty())
return;
Expand All @@ -7413,9 +7413,27 @@ void VisualServerRaster::set_boot_image(const Image& p_image, const Color& p_col
texture_set_data(texture,p_image);
rasterizer->canvas_begin_rect(Matrix32());
Rect2 imgrect(0,0,p_image.get_width(),p_image.get_height());
Rect2 screenrect=imgrect;
screenrect.pos+=((Size2(vr.width,vr.height)-screenrect.size)/2.0).floor();
rasterizer->canvas_draw_rect(screenrect,0,imgrect,texture,Color(1,1,1,0));
Rect2 screenrect;
if (p_scale) {

if (window_w > window_h) {
//scale horizontally
screenrect.size.y = window_h;
screenrect.size.x = imgrect.size.x * window_h / imgrect.size.y;
screenrect.pos.x = (window_w - screenrect.size.x)/2;

} else {
//scale vertically
screenrect.size.x = window_w;
screenrect.size.y = imgrect.size.y * window_w / imgrect.size.x;
screenrect.pos.y = (window_h - screenrect.size.y)/2;
}
} else {

screenrect=imgrect;
screenrect.pos+=((Size2(vr.width,vr.height)-screenrect.size)/2.0).floor();

}
rasterizer->canvas_draw_rect(screenrect,0,imgrect,texture,Color(1,1,1,1));
rasterizer->canvas_end_rect();

Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_raster.h
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ class VisualServerRaster : public VisualServer {

RID get_test_cube();

virtual void set_boot_image(const Image& p_image, const Color& p_color);
virtual void set_boot_image(const Image& p_image, const Color& p_color, bool p_scale);
virtual void set_default_clear_color(const Color& p_color);

VisualServerRaster(Rasterizer *p_rasterizer);
Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_wrap_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ class VisualServerWrapMT : public VisualServer {
FUNC1R(int,get_render_info,RenderInfo );
virtual bool has_feature(Features p_feature) const { return visual_server->has_feature(p_feature); }

FUNC2(set_boot_image,const Image& , const Color& );
FUNC3(set_boot_image,const Image& , const Color&,bool );
FUNC1(set_default_clear_color,const Color& );

FUNC0R(RID,get_test_cube );
Expand Down
2 changes: 1 addition & 1 deletion servers/visual_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ class VisualServer : public Object {
virtual void mesh_add_surface_from_mesh_data( RID p_mesh, const Geometry::MeshData& p_mesh_data);
virtual void mesh_add_surface_from_planes( RID p_mesh, const DVector<Plane>& p_planes);

virtual void set_boot_image(const Image& p_image, const Color& p_color)=0;
virtual void set_boot_image(const Image& p_image, const Color& p_color,bool p_scale)=0;
virtual void set_default_clear_color(const Color& p_color)=0;

enum Features {
Expand Down

0 comments on commit 3e20391

Please sign in to comment.