Skip to content

Commit

Permalink
Minor android porting. Call srand to get new random numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Jul 25, 2010
1 parent bcb7eee commit 4797c6c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion include/hx/CFFILoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ret IMPL_##name def_args \
name = (FUNC_##name)LoadFunc(#name); \
if (!name) \
{ \
__android_log_print(ANDROID_LOG_ERROR,"Could not resolve :" #name "\n"); \
__android_log_print(ANDROID_LOG_ERROR,"CFFILoader", "Could not resolve :" #name "\n"); \
} \
return name call_args; \
}\
Expand Down
9 changes: 8 additions & 1 deletion java/org/haxe/HXCPP.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
// Wrapper for native library

public class HXCPP {
static boolean mInit = false;

static public void run(String inClassName) {
System.loadLibrary(inClassName);
main();

if (!mInit)
{
mInit = true;
main();
}
}

public static native void main();
Expand Down
2 changes: 2 additions & 0 deletions src/Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ bool Math_obj::__Is(hxObject *inObj) const { return dynamic_cast<OBJ_ *>(inObj)!
void Math_obj::__boot()
{
Static(Math_obj::__mClass) = RegisterClass(HX_STRING(L"Math",4),TCanCast<Math_obj>,sMathFields,sNone, &__CreateEmpty,0 , 0 );

srand(time(0));
}

namespace hx
Expand Down
1 change: 0 additions & 1 deletion src/hx/CFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <string>



// Class for boxing external handles

namespace hx
Expand Down
6 changes: 6 additions & 0 deletions src/hx/GCInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ class GlobalAllocator
gThreadStateChangeLock->Unlock();
}
#endif

#ifdef ANDROID
//__android_log_print(ANDROID_LOG_INFO, "hxcpp", "Collect Done");
#endif
}

void CheckCollect()
Expand Down Expand Up @@ -1269,8 +1273,10 @@ void InternalCollect()
if (!sgAllocInit || !sgInternalEnable)
return;

#ifndef ANDROID
int dummy;
GetLocalAlloc()->SetTopOfStack(&dummy,false);
#endif
sGlobalAlloc->Collect();
}

Expand Down
68 changes: 36 additions & 32 deletions src/hx/StdLibs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ Dynamic Throw(Dynamic inDynamic)
namespace hx
{

typedef std::map<std::wstring,Resource> ResourceSet;
static ResourceSet sgResources;
//typedef std::map<std::wstring,Resource> ResourceSet;
//static ResourceSet sgResources;

Resource *sgResources;

void RegisterResources(Resource *inResources)
{
while(inResources->mData)
{
sgResources[inResources->mName.__s] = *inResources;
inResources++;
}
sgResources = inResources;
//while(inResources->mData)
//{
//sgResources[inResources->mName.__s] = *inResources;
//inResources++;
//}
}

}
Expand All @@ -53,39 +56,39 @@ using namespace hx;
Array<String> __hxcpp_resource_names()
{
Array<String> result(0,0);
for(ResourceSet::iterator i=sgResources.begin(); i!=sgResources.end();++i)
{
int len = i->first.length();
wchar_t *copy = hx::NewString(len);
memcpy(copy,i->first.c_str(), len*sizeof(wchar_t));
result->push( String(copy) );
}

for(Resource *reso = sgResources; reso->mData; reso++)
result->push( reso->mName );

return result;
}

String __hxcpp_resource_string(String inName)
{
ResourceSet::iterator i=sgResources.find(inName.__s);
if (i==sgResources.end())
return null();
return String((const char *) i->second.mData, i->second.mDataLength );
for(Resource *reso = sgResources; reso->mData; reso++)
{
if (reso->mName == inName)
return String((const char *) reso->mData, reso->mDataLength );
}
return null();
}

Array<unsigned char> __hxcpp_resource_bytes(String inName)
{
ResourceSet::iterator i=sgResources.find(inName.__s);
if (i==sgResources.end())
return null();
int len = i->second.mDataLength;
Array<unsigned char> result( len, 0);
memcpy( result->GetBase() , i->second.mData, len );
return result;
for(Resource *reso = sgResources; reso->mData; reso++)
{
if (reso->mName == inName)
{
int len = reso->mDataLength;
Array<unsigned char> result( len, 0);
memcpy( result->GetBase() , reso->mData, len );
return result;
}
}
}





// --- System ---------------------------------------------------------------------


Expand Down Expand Up @@ -264,9 +267,10 @@ Dynamic __hxcpp_parse_int(const String &inString)

#ifdef ANDROID
char buf[100];
for(int i=0;i<99 && i<inString.length;i++)
int i;
for(i=0;i<99 && i<inString.length;i++)
buf[i] = str[i];
buf[99] = '\0';
buf[i] = '\0';

char *end = 0;
if (hex)
Expand All @@ -291,9 +295,10 @@ double __hxcpp_parse_float(const String &inString)
const wchar_t *str = inString.__s;
#ifdef ANDROID
char buf[100];
for(int i=0;i<99 && i<inString.length;i++)
int i;
for(i=0;i<99 && i<inString.length;i++)
buf[i] = str[i];
buf[99] = '\0';
buf[i] = '\0';
char *end;
double result = strtod(buf,&end);
if (end==buf)
Expand Down Expand Up @@ -406,4 +411,3 @@ STATIC_HX_DEFINE_DYNAMIC_FUNC2(CppInt32___obj,make,return )




0 comments on commit 4797c6c

Please sign in to comment.