Skip to content

Commit 4797c6c

Browse files
committed
Minor android porting. Call srand to get new random numbers
1 parent bcb7eee commit 4797c6c

File tree

6 files changed

+53
-35
lines changed

6 files changed

+53
-35
lines changed

include/hx/CFFILoader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ ret IMPL_##name def_args \
200200
name = (FUNC_##name)LoadFunc(#name); \
201201
if (!name) \
202202
{ \
203-
__android_log_print(ANDROID_LOG_ERROR,"Could not resolve :" #name "\n"); \
203+
__android_log_print(ANDROID_LOG_ERROR,"CFFILoader", "Could not resolve :" #name "\n"); \
204204
} \
205205
return name call_args; \
206206
}\

java/org/haxe/HXCPP.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
// Wrapper for native library
44

55
public class HXCPP {
6+
static boolean mInit = false;
7+
68
static public void run(String inClassName) {
79
System.loadLibrary(inClassName);
8-
main();
10+
11+
if (!mInit)
12+
{
13+
mInit = true;
14+
main();
15+
}
916
}
1017

1118
public static native void main();

src/Math.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ bool Math_obj::__Is(hxObject *inObj) const { return dynamic_cast<OBJ_ *>(inObj)!
109109
void Math_obj::__boot()
110110
{
111111
Static(Math_obj::__mClass) = RegisterClass(HX_STRING(L"Math",4),TCanCast<Math_obj>,sMathFields,sNone, &__CreateEmpty,0 , 0 );
112+
113+
srand(time(0));
112114
}
113115

114116
namespace hx

src/hx/CFFI.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <string>
1111

1212

13-
1413
// Class for boxing external handles
1514

1615
namespace hx

src/hx/GCInternal.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,10 @@ class GlobalAllocator
758758
gThreadStateChangeLock->Unlock();
759759
}
760760
#endif
761+
762+
#ifdef ANDROID
763+
//__android_log_print(ANDROID_LOG_INFO, "hxcpp", "Collect Done");
764+
#endif
761765
}
762766

763767
void CheckCollect()
@@ -1269,8 +1273,10 @@ void InternalCollect()
12691273
if (!sgAllocInit || !sgInternalEnable)
12701274
return;
12711275

1276+
#ifndef ANDROID
12721277
int dummy;
12731278
GetLocalAlloc()->SetTopOfStack(&dummy,false);
1279+
#endif
12741280
sGlobalAlloc->Collect();
12751281
}
12761282

src/hx/StdLibs.cpp

+36-32
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ Dynamic Throw(Dynamic inDynamic)
3434
namespace hx
3535
{
3636

37-
typedef std::map<std::wstring,Resource> ResourceSet;
38-
static ResourceSet sgResources;
37+
//typedef std::map<std::wstring,Resource> ResourceSet;
38+
//static ResourceSet sgResources;
39+
40+
Resource *sgResources;
3941

4042
void RegisterResources(Resource *inResources)
4143
{
42-
while(inResources->mData)
43-
{
44-
sgResources[inResources->mName.__s] = *inResources;
45-
inResources++;
46-
}
44+
sgResources = inResources;
45+
//while(inResources->mData)
46+
//{
47+
//sgResources[inResources->mName.__s] = *inResources;
48+
//inResources++;
49+
//}
4750
}
4851

4952
}
@@ -53,39 +56,39 @@ using namespace hx;
5356
Array<String> __hxcpp_resource_names()
5457
{
5558
Array<String> result(0,0);
56-
for(ResourceSet::iterator i=sgResources.begin(); i!=sgResources.end();++i)
57-
{
58-
int len = i->first.length();
59-
wchar_t *copy = hx::NewString(len);
60-
memcpy(copy,i->first.c_str(), len*sizeof(wchar_t));
61-
result->push( String(copy) );
62-
}
59+
60+
for(Resource *reso = sgResources; reso->mData; reso++)
61+
result->push( reso->mName );
62+
6363
return result;
6464
}
6565

6666
String __hxcpp_resource_string(String inName)
6767
{
68-
ResourceSet::iterator i=sgResources.find(inName.__s);
69-
if (i==sgResources.end())
70-
return null();
71-
return String((const char *) i->second.mData, i->second.mDataLength );
68+
for(Resource *reso = sgResources; reso->mData; reso++)
69+
{
70+
if (reso->mName == inName)
71+
return String((const char *) reso->mData, reso->mDataLength );
72+
}
73+
return null();
7274
}
7375

7476
Array<unsigned char> __hxcpp_resource_bytes(String inName)
7577
{
76-
ResourceSet::iterator i=sgResources.find(inName.__s);
77-
if (i==sgResources.end())
78-
return null();
79-
int len = i->second.mDataLength;
80-
Array<unsigned char> result( len, 0);
81-
memcpy( result->GetBase() , i->second.mData, len );
82-
return result;
78+
for(Resource *reso = sgResources; reso->mData; reso++)
79+
{
80+
if (reso->mName == inName)
81+
{
82+
int len = reso->mDataLength;
83+
Array<unsigned char> result( len, 0);
84+
memcpy( result->GetBase() , reso->mData, len );
85+
return result;
86+
}
87+
}
8388
}
8489

8590

8691

87-
88-
8992
// --- System ---------------------------------------------------------------------
9093

9194

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

265268
#ifdef ANDROID
266269
char buf[100];
267-
for(int i=0;i<99 && i<inString.length;i++)
270+
int i;
271+
for(i=0;i<99 && i<inString.length;i++)
268272
buf[i] = str[i];
269-
buf[99] = '\0';
273+
buf[i] = '\0';
270274

271275
char *end = 0;
272276
if (hex)
@@ -291,9 +295,10 @@ double __hxcpp_parse_float(const String &inString)
291295
const wchar_t *str = inString.__s;
292296
#ifdef ANDROID
293297
char buf[100];
294-
for(int i=0;i<99 && i<inString.length;i++)
298+
int i;
299+
for(i=0;i<99 && i<inString.length;i++)
295300
buf[i] = str[i];
296-
buf[99] = '\0';
301+
buf[i] = '\0';
297302
char *end;
298303
double result = strtod(buf,&end);
299304
if (end==buf)
@@ -406,4 +411,3 @@ STATIC_HX_DEFINE_DYNAMIC_FUNC2(CppInt32___obj,make,return )
406411

407412

408413

409-

0 commit comments

Comments
 (0)