Skip to content

Commit

Permalink
Merge pull request #2 from okamstudio/master
Browse files Browse the repository at this point in the history
pull
  • Loading branch information
choikwa committed May 31, 2015
2 parents ec93668 + d5348ee commit 6813a1f
Show file tree
Hide file tree
Showing 63 changed files with 3,982 additions and 629 deletions.
3 changes: 2 additions & 1 deletion core/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
//try to load settings in ascending through dirs shape!

//tries to open pack, but only first time
if (first_time && _load_resource_pack(current_dir+"/data.pck")) {
if (first_time && (_load_resource_pack(current_dir+"/data.pck") || _load_resource_pack(current_dir+"/data.pcz") )) {
if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {

_load_settings("res://override.cfg");
Expand Down Expand Up @@ -1460,6 +1460,7 @@ Globals::Globals() {
custom_prop_info["display/orientation"]=PropertyInfo(Variant::STRING,"display/orientation",PROPERTY_HINT_ENUM,"landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
custom_prop_info["render/mipmap_policy"]=PropertyInfo(Variant::INT,"render/mipmap_policy",PROPERTY_HINT_ENUM,"Allow,Allow For Po2,Disallow");
custom_prop_info["render/thread_model"]=PropertyInfo(Variant::INT,"render/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
custom_prop_info["physics_2d/thread_model"]=PropertyInfo(Variant::INT,"physics_2d/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
set("display/emulate_touchscreen",false);

using_datapack=false;
Expand Down
10 changes: 7 additions & 3 deletions core/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,10 @@ Error Image::_decompress_bc() {
return OK;
}

bool Image::is_compressed() const {
return format>=FORMAT_BC1;
}


Image Image::decompressed() const {

Expand Down Expand Up @@ -1998,7 +2002,7 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
}


Image (*Image::_png_mem_loader_func)(const uint8_t*)=NULL;
Image (*Image::_png_mem_loader_func)(const uint8_t*,int)=NULL;
void (*Image::_image_compress_bc_func)(Image *)=NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *)=NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *)=NULL;
Expand Down Expand Up @@ -2167,15 +2171,15 @@ void Image::fix_alpha_edges() {

}

Image::Image(const uint8_t* p_png) {
Image::Image(const uint8_t* p_png,int p_len) {

width=0;
height=0;
mipmaps=0;
format=FORMAT_GRAYSCALE;

if (_png_mem_loader_func) {
*this = _png_mem_loader_func(p_png);
*this = _png_mem_loader_func(p_png,p_len);
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Image {
/* INTERPOLATE GAUSS */
};

static Image (*_png_mem_loader_func)(const uint8_t* p_png);
static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size);
static void (*_image_compress_bc_func)(Image *);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
Expand Down Expand Up @@ -335,6 +335,7 @@ class Image {
Image compressed(int p_mode); /* from the Image::CompressMode enum */
Error decompress();
Image decompressed() const;
bool is_compressed() const;

void fix_alpha_edges();
void premultiply_alpha();
Expand All @@ -349,7 +350,7 @@ class Image {
Image get_rect(const Rect2& p_area) const;

static void set_compress_bc_func(void (*p_compress_func)(Image *));
Image(const uint8_t* p_mem_png);
Image(const uint8_t* p_mem_png, int p_len=-1);
Image(const char **p_xpm);
~Image();

Expand Down
8 changes: 8 additions & 0 deletions core/io/file_access_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ bool FileAccessMemory::file_exists(const String& p_name) {
}


Error FileAccessMemory::open_custom(const uint8_t* p_data, int p_len) {

data=(uint8_t*)p_data;
length=p_len;
pos=0;
return OK;
}

Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) {

ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);
Expand Down
1 change: 1 addition & 0 deletions core/io/file_access_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class FileAccessMemory : public FileAccess {
static void register_file(String p_name, Vector<uint8_t> p_data);
static void cleanup();

virtual Error open_custom(const uint8_t* p_data, int p_len); ///< open a file
virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
Expand Down
21 changes: 18 additions & 3 deletions core/io/file_access_zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "file_access_zip.h"

#include "core/os/file_access.h"
#include "core/os/copymem.h"

ZipArchive* ZipArchive::instance = NULL;

Expand Down Expand Up @@ -103,9 +104,17 @@ static int godot_testerror(voidpf opaque, voidpf stream) {
return f->get_error()!=OK?1:0;
};

static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) {

return memalloc(items * size);
};

static void godot_free(voidpf opaque, voidpf address) {

memfree(address);
};

}; // extern "C"

void ZipArchive::close_handle(unzFile p_file) const {

Expand All @@ -125,6 +134,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
ERR_FAIL_COND_V(!f, NULL);

zlib_filefunc_def io;
zeromem(&io, sizeof(io));

io.opaque = f;
io.zopen_file = godot_open;
Expand All @@ -136,9 +146,13 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
io.zclose_file = godot_close;
io.zerror_file = godot_testerror;

io.alloc_mem = godot_alloc;
io.free_mem = godot_free;

unzFile pkg = unzOpen2(packages[file.package].filename.utf8().get_data(), &io);
ERR_FAIL_COND_V(!pkg, NULL);
unzGoToFilePos(pkg, &file.file_pos);
int unz_err = unzGoToFilePos(pkg, &file.file_pos);
ERR_FAIL_COND_V(unz_err != UNZ_OK, NULL);
if (unzOpenCurrentFile(pkg) != UNZ_OK) {

unzClose(pkg);
Expand All @@ -150,7 +164,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {

bool ZipArchive::try_open_pack(const String& p_name) {

//printf("opening pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
if (p_name.extension().nocasecmp_to("zip") != 0 && p_name.extension().nocasecmp_to("pcz") != 0)
return false;

Expand Down Expand Up @@ -198,7 +212,8 @@ bool ZipArchive::try_open_pack(const String& p_name) {
files[fname] = f;

uint8_t md5[16]={0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0};
PackedData::get_singleton()->add_path(p_name, fname, 0, 0, md5, this);
PackedData::get_singleton()->add_path(p_name, fname, 1, 0, md5, this);
//printf("packed data add path %ls, %ls\n", p_name.c_str(), fname.c_str());

if ((i+1)<gi.number_entry) {
unzGoToNextFile(zfile);
Expand Down
2 changes: 1 addition & 1 deletion core/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ Error Object::connect(const StringName& p_signal, Object *p_to_object, const Str
if (!s) {
bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal);
if (!signal_is_valid) {
ERR_EXPLAIN("Attempt to connect to nonexistent signal: "+p_signal);
ERR_EXPLAIN("Attempt to connect nonexistent signal '"+p_signal+"' to method '"+p_to_method+"'");
ERR_FAIL_COND_V(!signal_is_valid,ERR_INVALID_PARAMETER);
}
signal_map[p_signal]=Signal();
Expand Down
8 changes: 6 additions & 2 deletions core/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
case COLOR: {

static const Type valid[] = {
//STRING,
//INT,
STRING,
INT,
NIL,
};

Expand Down Expand Up @@ -1653,6 +1653,10 @@ Variant::operator Color() const {

if (type==COLOR)
return *reinterpret_cast<const Color*>(_data._mem);
else if (type==STRING)
return Color::html( operator String() );
else if (type==INT)
return Color::hex( operator int() );
else
return Color();
}
Expand Down
7 changes: 7 additions & 0 deletions demos/2d/motion/engine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@

name="Motion Test"
main_scene="res://motion.scn"

[display]

width=800
height=600
stretch_mode="2d"
stretch_aspect="keep"
22 changes: 18 additions & 4 deletions drivers/png/image_loader_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "print_string.h"
#include "os/os.h"



void ImageLoaderPNG::_read_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) {

FileAccess *f = (FileAccess*)png_get_io_ptr(png_ptr);
Expand Down Expand Up @@ -253,6 +255,7 @@ void ImageLoaderPNG::get_recognized_extensions(List<String> *p_extensions) const
struct PNGReadStatus {

int offset;
int size;
const unsigned char *image;
};

Expand All @@ -261,17 +264,26 @@ static void user_read_data(png_structp png_ptr,png_bytep data, png_size_t p_leng
PNGReadStatus *rstatus;
rstatus=(PNGReadStatus*)png_get_io_ptr(png_ptr);

memcpy(data,&rstatus->image[rstatus->offset],p_length);
rstatus->offset+=p_length;
int to_read=p_length;
if (rstatus->size>=0) {
to_read = MIN( p_length, rstatus->size - rstatus->offset);
}
memcpy(data,&rstatus->image[rstatus->offset],to_read);
rstatus->offset+=to_read;

if (to_read<p_length) {
memset(&data[to_read],0,p_length-to_read);
}
}


static Image _load_mem_png(const uint8_t* p_png) {
static Image _load_mem_png(const uint8_t* p_png,int p_size) {


PNGReadStatus prs;
prs.image=p_png;
prs.offset=0;
prs.size=p_size;

Image img;
Error err = ImageLoaderPNG::_load_image(&prs,user_read_data,&img);
Expand All @@ -283,9 +295,10 @@ static Image _load_mem_png(const uint8_t* p_png) {

static Image _lossless_unpack_png(const DVector<uint8_t>& p_data) {

int len = p_data.size();
DVector<uint8_t>::Read r = p_data.read();
ERR_FAIL_COND_V(r[0]!='P' || r[1]!='N' || r[2]!='G' || r[3]!=' ',Image());
return _load_mem_png(&r[4]);
return _load_mem_png(&r[4],len-4);

}

Expand Down Expand Up @@ -424,6 +437,7 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) {

ImageLoaderPNG::ImageLoaderPNG() {


Image::_png_mem_loader_func=_load_mem_png;
Image::lossless_unpacker=_lossless_unpack_png;
Image::lossless_packer=_lossless_pack_png;
Expand Down
3 changes: 3 additions & 0 deletions drivers/png/image_loader_png.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class ImageLoaderPNG : public ImageFormatLoader {
static void _read_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length);



public:


static Error _load_image(void *rf_up,png_rw_ptr p_func,Image *p_image);
virtual Error load_image(Image *p_image,FileAccess *f);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
Expand Down
2 changes: 2 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,8 @@ bool Main::iteration() {
message_queue->flush();

PhysicsServer::get_singleton()->step(frame_slice*time_scale);

Physics2DServer::get_singleton()->end_sync();
Physics2DServer::get_singleton()->step(frame_slice*time_scale);

time_accum-=frame_slice;
Expand Down
3 changes: 2 additions & 1 deletion platform/android/os_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_
//
physics_server = memnew( PhysicsServerSW );
physics_server->init();
physics_2d_server = memnew( Physics2DServerSW );
//physics_2d_server = memnew( Physics2DServerSW );
physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
physics_2d_server->init();

input = memnew( InputDefault );
Expand Down
1 change: 1 addition & 0 deletions platform/android/os_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
#include "servers/audio/audio_server_sw.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
#include "servers/physics_2d/physics_2d_server_wrap_mt.h"
#include "servers/visual/rasterizer.h"


Expand Down
6 changes: 6 additions & 0 deletions platform/iphone/game_center.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class GameCenter : public Object {

Error post_score(Variant p_score);
Error award_achievement(Variant p_params);
void reset_achievements();
void request_achievements();
void request_achievement_descriptions();
Error show_game_center(Variant p_params);

void game_center_closed();

int get_pending_event_count();
Variant pop_pending_event();
Expand Down
Loading

0 comments on commit 6813a1f

Please sign in to comment.