Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - This code is behaving strangely
Page 1 of 1

PostPosted: Mon Jun 23, 2003 2:27 am
by Glasswalker
Ok this is acting wierd...
My event handling loop seems to simply lock up the machine...

I can run my program, and the debug output works fine, right up until I reach my event handler routine... then it does nothing... it does not freeze up, but it does go to 100% cpu usage and battery is drained drastically... And it takes one minute for the window close to respond...

The odd part is:

it does not lock down, until an event is passed... EG: if I run the program, it runs smoothly, I can close, and pull down file menu, view the console whatever all smoothly...

BUT... if I tap in the screen, or on any control it starts the slowdown thing...

The odd part is as I said, even before I tap the screen, if I put a debug line in the first line of the check for event routine, it never executes the code...

It is confusing me...

Anyway I am sure it is some stupid little thing I am overlooking... I have stared at it for 2 days now, but as others have pointed out I am not the most observant of people :)

be ready for a long read, since I have no idea what is causing the error, I am posting the whole program code...

//===============================================================
//Preprocessor Defines for Neural Net and Bug Configuration
//===============================================================
#define NN_SIZE 20
#define NN_LAYERS 4 //Including the input layer and output layer.
#define NUM_BUGS 4

//===============================================================
//Function Declarations
//===============================================================
loadgraphics();
drawtile(int tileid,int x,int y);
init_graphics_array();
init_game();
main_program_loop();
draw_gui();
draw_map();
init_map();
event_handler();
mouse_handler(int x,int y);
gui_handler(int object);
DrawNewCtrl(string ctrltype,string ctrlname,int x, int y, int w, int h);
strint(string str);
core_program();

//===============================================================
//Struct Definitions
//===============================================================

struct synapse_s
{
int weight;
int fired_short;
int fired_long;
};

struct neuron_s
{
int value;
struct synapse_s synapse[NN_SIZE];
};

struct nn_s
{
struct neuron_s neuron[NN_SIZE];
};

struct brain_s
{
struct nn_s nn_layer[NN_LAYERS];
};

struct smell_s
{
int food;
int bugs;
int toxin;
};

struct memory_s
{
int food;
int water;
int bugs;
int toxin;
int hazard;
int home;
};

struct bug_s
{
struct brain_s brain;
int fitness;
int generation;
string name;
int x;
int y;
int oldx;
int oldy;
int facing;
int food;
int water;
int seenfriend;
int social;
int toxin;
int energy;
int health;
int vision;
struct smell_s smell;
struct memory_s memory;
};

//===============================================================
//Global Variable Declarations
//===============================================================
int image_handle[255];
string cwd;
string image_file[255];
int num_images;
int map[7500];
int ctrlcount;
int quitnow;

//===============================================================
//Program Entry Point (Main Function)
//===============================================================
main()
{
roundrect(128,98,465,162,8,8);
text(130,100,"PLEASE WAIT... INITIALIZING BUGS... ");
text(130,115,"=====================================");
text(130,130,"This takes a long time because the ");
text(130,145,"Bugs take up a huge memory footprint.");
core_program();
}

core_program()
{
// struct bug_s bug[NUM_BUGS];
init_game();
main_program_loop();
}

//===============================================================
//MAIN PROGRAM LOOP
//===============================================================
main_program_loop()
{
int evt;
quitnow = 0;
puts("Beginning Main Game Loop...\r\n");
puts("===========================================\r\n");
alert(quitnow);
while(quitnow==0);
{
sleep(0);
evt = event(0);
if(evt>0&&evt<11)
puts(evt+"\r\n");
// event_handler();
}
puts("===========================================\r\n");
puts("Main Loop Complete... \r\n\r\n");

}

//===============================================================
//Program Function Library
//===============================================================

strint(string str)
{
int outval;
outval = (int)str;
return outval;
}

DrawNewCtrl(string ctrltype,string ctrlname,int x, int y, int w, int h)
{
int ctrlid,ctrlmode,ctrlmode2;
ctrlcount++;
ctrlmode=1;
ctrlmode2=1;
x = x + 2;
y = y + 26;
if(strncmp(ctrltype,"BUTTON",5)==0)
ctrlmode2=0;
if(strncmp(ctrltype,"LISTBOX",5)==0)
ctrlmode=1;
ctrlid = createctrl(ctrltype,ctrlname,ctrlmode,ctrlmode2,x,y,w,h,ctrlcount+500);
wndshow(ctrlid,5);
return ctrlid;
}

mouse_handler(int x,int y)
{
alert("X: "+x+" Y: "+y);
}

gui_handler(int object)
{

}

event_handler()
{
int evt;
evt = event(0);
if(evt>0&&evt<11)
puts(evt+"\r\n");
if(evt==2)
mouse_handler(penx(),peny());
if(evt==5)
gui_handler(guiid());
}

init_map()
{
int x,y;
for(x=0;x<50;x++)
{
for(y=0;y<15;y++)
map[x*y]=0;
}
}

draw_map()
{
int x,y;
for(x=0;x<50;x++)
{
for(y=0;y<15;y++)
{
drawtile(map[x*y],x,y);
}
}
}

init_game()
{
puts("Beginning Game Initialization Sequence...\r\n");
puts("===========================================\r\n");
graph_on();
draw_gui();
init_graphics_array();
loadgraphics();
init_map();
draw_map();
puts("===========================================\r\n");
puts("Initialization Sequence Complete... \r\n\r\n");
}

draw_gui()
{
int ctlid;
rect(2,57,506,211);
ctlid=DrawNewCtrl("LISTBOX","Map Painter",504,2,100,100);

}

init_graphics_array()
{
string imagesfolder;
puts("Initializing Graphics Array..."+"\r\n");
cwd = "\\Program Files\\Bugz\\";
puts("CWD is set to: "+cwd+"\r\n");
imagesfolder = cwd+"Images\\";
puts("Images folder is set to: "+imagesfolder+"\r\n");
num_images = 9;
puts("Num_Images set to: "+num_images+"\r\n");
puts("Storing Image Filenames In Array..."+"\r\n");
image_file[0] = imagesfolder+"grass.bmp";
image_file[1] = imagesfolder+"food.bmp";
image_file[2] = imagesfolder+"toxin.bmp";
image_file[3] = imagesfolder+"hazard.bmp";
image_file[4] = imagesfolder+"water.bmp";
image_file[5] = imagesfolder+"bugup.bmp";
image_file[6] = imagesfolder+"bugright.bmp";
image_file[7] = imagesfolder+"bugdown.bmp";
image_file:?: = imagesfolder+"bugleft.bmp";
puts("Image Array Initialized Successfully..."+"\r\n");
}

loadgraphics()
{
int i;
puts("Loading Graphics Data To Memory..."+"\r\n");
puts("==================================="+"\r\n");
for(i=0;i<num_images;i++)
{
image_handle[i] = imgload(image_file[i],100,10,10);
if(image_handle[i]==0)
puts("Error Loading Image File: "+image_file[i]+"\r\n");
if(image_handle[i]!=0)
puts("Successfully loaded image file: "+image_file[i]+" into handle: "+image_handle[i]+"\r\n");
}
puts("==================================="+"\r\n");
puts("Image Data Loaded Successfully..."+"\r\n");
}

drawtile(int tileid,int x,int y)
{
int newx,newy;
if(x<50&&x>=0&&y<15&&y>=0)
{
newx = (x*10)+4;
newy = (y*10)+59;
if(imgbitblt(image_handle[tileid],newx,newy,10,10,0,0,0)==-1)
puts("Error Drawing Image Handle: "+image_handle[tileid]+"\r\n");
}
}

PostPosted: Tue Jun 24, 2003 11:38 pm
by Glasswalker
Anybody have any ideas on this one? I am pretty sure it has to do with the event handler code, but not sure...

PostPosted: Thu Jun 26, 2003 12:35 pm
by joh.becker
You can try to reduce your code to the absolute minimum around the event handler to eliminate impacts (bugs) of the compiler coming from somewhere unrelated.

Johannes

PostPosted: Wed Jul 02, 2003 1:29 am
by Glasswalker
Hello again, I just tried the last suggestion on my code... I stripped out all the preprocessor stuff (which made compiling extremely faster...)

Anyway, I stripped down every single thing but the affected code, but it still did not fix the problem... the exact same thing was happening... So then I rewrote the event handler code... (still practically the same, but I just redid it) And then it worked!!! so I thought great! I can just paste in that code to the original program... so I did... and the original program is still doing the exact same thing... So I stripped down the preprocessor stuff on it... still the same problem...

I noticed that the main loop, where the sleep(0) is, it gets to the puts line right before the while statment that begins the loop, but it never executes any code after the while loop... nothing inside the loop gets executed... I put an alert there, but it does not pop no matter what...

Anyway, here is my updated code... that still does not work...

I really need some help with this, I have written like 4 or 5 programs that use the gui, and now this program can't have a simple event handler? and the code is an exact copy (even a copy and paste type) of the working code! I don't get it...

Anyway, here is the code:

//===============================================================
//Preprocessor Defines for Neural Net and Bug Configuration
//===============================================================
#define NN_SIZE 20
#define NN_LAYERS 4 //Including the input layer and output layer.
#define NUM_BUGS 4

//===============================================================
//Function Declarations
//===============================================================
loadgraphics();
drawtile(int tileid,int x,int y);
init_graphics_array();
init_game();
main_program_loop();
draw_gui();
draw_map();
init_map();
event_handler(int evt);
mouse_handler(int x,int y);
gui_handler(int object);
DrawNewCtrl(string ctrltype,string ctrlname,int x, int y, int w, int h);
strint(string str);

//===============================================================
//Struct Definitions
//===============================================================

struct synapse_s
{
int weight;
int fired_short;
int fired_long;
};

struct neuron_s
{
int value;
struct synapse_s synapse[NN_SIZE];
};

struct nn_s
{
struct neuron_s neuron[NN_SIZE];
};

struct brain_s
{
struct nn_s nn_layer[NN_LAYERS];
};

struct smell_s
{
int food;
int bugs;
int toxin;
};

struct memory_s
{
int food;
int water;
int bugs;
int toxin;
int hazard;
int home;
};

struct bug_s
{
struct brain_s brain;
int fitness;
int generation;
string name;
int x;
int y;
int oldx;
int oldy;
int facing;
int food;
int water;
int seenfriend;
int social;
int toxin;
int energy;
int health;
int vision;
struct smell_s smell;
struct memory_s memory;
};

//===============================================================
//Global Variable Declarations
//===============================================================
int image_handle[255];
string cwd;
string image_file[255];
int num_images;
int map[7500];
int ctrlcount;
int quitnow;

//===============================================================
//Program Entry Point (Main Function)
//===============================================================
main()
{
// struct bug_s bug[NUM_BUGS];
roundrect(128,98,465,162,8,8);
text(130,100,"PLEASE WAIT... INITIALIZING BUGS... ");
text(130,115,"=====================================");
text(130,130,"This takes a long time because the ");
text(130,145,"Bugs take up a huge memory footprint.");
init_game();
main_program_loop();
}

//===============================================================
//MAIN PROGRAM LOOP
//===============================================================
main_program_loop()
{
int evt;
quitnow = 0;
puts("Beginning Main Game Loop...\r\n");
puts("===========================================\r\n");
while(quitnow==0);
{
alert("entering main game loop");
sleep(0);
evt=event(0);
event_handler(evt);
}
puts("===========================================\r\n");
puts("Main Loop Complete... \r\n\r\n");

}

//===============================================================
//Program Function Library
//===============================================================

strint(string str)
{
int outval;
outval = (int)str;
return outval;
}

DrawNewCtrl(string ctrltype,string ctrlname,int x, int y, int w, int h)
{
int ctrlid,ctrlmode,ctrlmode2;
ctrlcount++;
ctrlmode=1;
ctrlmode2=1;
x = x + 2;
y = y + 26;
if(strncmp(ctrltype,"BUTTON",5)==0)
ctrlmode2=0;
if(strncmp(ctrltype,"LISTBOX",5)==0)
ctrlmode=1;
ctrlid = createctrl(ctrltype,ctrlname,ctrlmode,ctrlmode2,x,y,w,h,ctrlcount+500);
wndshow(ctrlid,5);
return ctrlid;
}

mouse_handler(int x,int y)
{
alert("X: "+x+" Y: "+y);
}

gui_handler(int object)
{

}

event_handler(int evt)
{
if(evt==4)
mouse_handler(penx(),peny());
if(evt==8)
gui_handler(guiid());
}

init_map()
{
int x,y;
for(x=0;x<50;x++)
{
for(y=0;y<15;y++)
map[x*y]=0;
}
}

draw_map()
{
int x,y;
for(x=0;x<50;x++)
{
for(y=0;y<15;y++)
{
drawtile(map[x*y],x,y);
}
}
}

init_game()
{
puts("Beginning Game Initialization Sequence...\r\n");
puts("===========================================\r\n");
graph_on();
draw_gui();
init_graphics_array();
loadgraphics();
init_map();
draw_map();
puts("===========================================\r\n");
puts("Initialization Sequence Complete... \r\n\r\n");
}

draw_gui()
{
int ctlid;
rect(2,57,506,211);
ctlid=DrawNewCtrl("LISTBOX","Map Painter",504,2,100,100);

}

init_graphics_array()
{
string imagesfolder;
puts("Initializing Graphics Array..."+"\r\n");
cwd = "\\Program Files\\Bugz\\";
puts("CWD is set to: "+cwd+"\r\n");
imagesfolder = cwd+"Images\\";
puts("Images folder is set to: "+imagesfolder+"\r\n");
num_images = 9;
puts("Num_Images set to: "+num_images+"\r\n");
puts("Storing Image Filenames In Array..."+"\r\n");
image_file[0] = imagesfolder+"grass.bmp";
image_file[1] = imagesfolder+"food.bmp";
image_file[2] = imagesfolder+"toxin.bmp";
image_file[3] = imagesfolder+"hazard.bmp";
image_file[4] = imagesfolder+"water.bmp";
image_file[5] = imagesfolder+"bugup.bmp";
image_file[6] = imagesfolder+"bugright.bmp";
image_file[7] = imagesfolder+"bugdown.bmp";
image_file:?: = imagesfolder+"bugleft.bmp";
puts("Image Array Initialized Successfully..."+"\r\n");
}

loadgraphics()
{
int i;
puts("Loading Graphics Data To Memory..."+"\r\n");
puts("==================================="+"\r\n");
for(i=0;i<num_images;i++)
{
image_handle[i] = imgload(image_file[i],100,10,10);
if(image_handle[i]==0)
puts("Error Loading Image File: "+image_file[i]+"\r\n");
if(image_handle[i]!=0)
puts("Successfully loaded image file: "+image_file[i]+" into handle: "+image_handle[i]+"\r\n");
}
puts("==================================="+"\r\n");
puts("Image Data Loaded Successfully..."+"\r\n");
}

drawtile(int tileid,int x,int y)
{
int newx,newy;
if(x<50&&x>=0&&y<15&&y>=0)
{
newx = (x*10)+4;
newy = (y*10)+59;
if(imgbitblt(image_handle[tileid],newx,newy,10,10,0,0,0)==-1)
puts("Error Drawing Image Handle: "+image_handle[tileid]+"\r\n");
}
}

PostPosted: Mon Jul 07, 2003 12:31 am
by Glasswalker
Wow... it has been over 1 week, and still no reply...

Am I ever going to get this to work?

Is pocketC CE dead completely?

If it is completely dead, why don't they release the source as a download to registered users so that they can at least try and update it themselves? Or why not release the current (alpha? beta?) ver of pocketC CE V4 (I know I overheard someone talking that it was working, just needed some tweaking)

CE is getting better... and the CE machines are the fastest and most powerful and versatile units out there... Why not support them?

Anyway... Hopefully someone will help me out soon...

Please someone help me! :) I am a paying customer... Where did the customer support go? :)

PostPosted: Mon Jul 07, 2003 5:44 pm
by joh.becker
Hi,

Try that one below. Difference is the main event loop. Why your does not work I dont know, but this should do it now.
Johannes

// snip
main_program_loop()
{
int evt;
quitnow = 0;
puts("Beginning Main Game Loop...\r\n");
puts("===========================================\r\n");
//JB while(quitnow==0);
while(1)
{
alert("entering main game loop");
sleep(0);
evt=event(0);
event_handler(evt);

quitnow = 1; // to show the exit
if (quitnow == 1) //this is the real exit
break;
}
puts("===========================================\r\n");
puts("Main Loop Complete... \r\n\r\n");

}
// snip

PostPosted: Thu Jul 24, 2003 6:52 pm
by guy
Do you need to use event(0) rather than event(1)?

event(0) will kill your machine and flatten the battery.

You don't seem to be doing any other processing when the event handler is running, so it's far better if you use event(1) so that it actually waits for events rather than returning PM_NONE events so fast that you can't handle them.

You should only really use event(0) to purge the event queue down to a particular message type or PM_NONE.

If you want to run other parts of the code whilst the event loop is running then set a timer and call the other code when you get PM_TIMER events.

> My event handling loop seems to simply lock up the machine...
> ...
> evt = event(0);

Yes.

event(0) = Lock up machine
event(1) = Normal event processing



Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum