Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Short Question Thread!

Author
Message
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 05:05 Edited at: 16th Oct 2017 05:07
Short Question Thread for Everyone.

I am pretty new to DBPro only a little over a month or so have I been using the language and as such I have a million questions but don't feel that they particularly warrant their own thread so I felt it prudent to make a short question thread for not only myself but I encourage others to post their simple short questions here in this thread as well.

RULE:
Keep it short and simple, the KISS principle always hold true. Feel free to use this thread for questions which can be answered with a single reply or two.

Threads such as this generally get filled up to contain a wealth of information and I hope this turns out the same.




I Will start it out as I had a question in mind that I am almost sure someone here should be able to answer with relative ease. Can a Function Pointer be added to a type to include a specific function into a Type Declaration? IE: I have a Type, Its a Neuron, as such I wish for a specific function to be called once certain conditions are meet, mainly once the neuron has enough activation energy I wish for a function to be called. Now I could hard code this in with some If statements and an integer value so if my value is 1 it calls function A if its 2 it calls B etc but I feel If I could associate a pointer value so that it calls function that I have assigned to it then all will be great.
Same goes for Arrays. I am pretty sure I can assign a pointer to the array which should allow me to pass the Array to Functions which we concluded in recent threads that its not possible to pass them directly.
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 16th Oct 2017 07:34
The matrix1 plugin made by IanM can work with funktion pointers and brings some other neat stuff to dbpro:
https://forum.thegamecreators.com/thread/85209

as an alternative i make a FID field and make a function with a select statement.

you can also use strings, but you have to free any UDT string before you close the programm to keep things clean with free string$()
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 20:09 Edited at: 16th Oct 2017 20:12
TY, Something to look into. The select:case or a string of IF statements is something I am attempting to avoid by using pointer since it will allow the function to be contained directly in the UDT almost like a Class system.

This Right here Looks like it should get me there with ease. I should just be able to include the function into a type declaration

with no problem.






Has anyone ever had DBPro just stop compiling? It started last night, normally if I restart the editor it works again but this time nothing. I click the run button (Save + Compile) and nothing happens. IDK What is going on.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 20:15 Edited at: 16th Oct 2017 20:32
I can even KEYMASH and put something like asdgasdfgadfAHDSFAJDGAG INTO it and NOTHING happens. No error or nothing. Its not even compiling or attempting to compile and there is no reason why. It just started. It worked one time. I wrote some more code, tried to run it again and nothing this time.

[edit]


OK.... I delete this....


and it works..... The gibberish is my keymashing attempt. .... It makes no sense. You can see I commented out almost everything in order to get it to work and nothing did The DO-LOOP Seems to be causing it to just NOT COMPILE. No error, nothing just not compiling.

I can TOTALLY Comment EVERYTHING out and it wont compile but if I delete that chunk it compiles WTF Is going on here.



[EDIT2]

This is doing it and I even have it commented out....

//#constant e# = 2.718281828

If that line is there commented or not the compiler does not even start. Does anyone elses do this because its not the first time I seen this with constants.


It seems its only doing it if the e has # after it.... Is this a bug?

//#constant e# = 2.718281828 No Worky
//#constant e = 2.718281828 Worky

Its gotta be a bug right? I mean it shouldnt matter if I have it commented out anyway yet the compiler does not even start if I have the hashtag there.
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 16th Oct 2017 21:04
Ok, some strange behavior right there. But a constant does not work like a normal variable. It's a precompiler command (or something linke that):

#constant e 2.718
print e
wait key

Will be changed to:

print 2.718
wait key

before compiling. well there is a Chance that it actually changes it to this:

print 2.718
wait k2.718y

If you want to use constants, use longer names or just use globals.
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 22:00
It didn't matter about name size I changed it to see if E was what was getting in the way but it was the Hashtag doing it. I figured it had something to do with a precompiling issue. Its def a bug. Have you tried it as well and did it do the same for you. I guess the pre-compiler can not recognize the hashtag which more then likely is shutting it down due to an error however the precompiler must not have a very good error reporter so instead of telling me whats wrong it just stops working.

I wanted to use Constants because Globals they have to search through the memory in order for it to point to the area in which the value is stored in the variable yet Constants replace the value when it finds the Variable with the value you determined...

IE:
Global E
e+10 = .... point to the area of memory, find it in the stack, pop it to the registers read the value then do the math by adding the register value to the other register which is 10

Constant E

Just makes two registers, one having the value of E and the other 10 then it adds them together. This GREATLY Improves speed because it would cut back on god knows how many tics by eliminating the need to handle the stack.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 16th Oct 2017 22:52
The constant syntax is

#constant token value

Something# denotes a float variable

So 'e# = 2.718281828' is attempting to register a constant token 'e#' of value ' = 2.718281828' and likely causes a resolution conflict between the explicit token of 'e#' and an implicit variable of 'e#'

Even if this actually resolved in precompilation it will result in invalid syntax:

Print e#*10

Precompiles to:

Print = 2.718281828*10

'e$' or 'e$ =' will likely cause a similar issue. (string variables)

# $ . are reserved tokens and should not be used in naming.

Constant declarations do not need = to assign value.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 23:04
That's apparently not the issue it seems because I just opened some other code of mine which is having the same issue except there is no Hashtag on the variable.

Does not work
#constant player = 5
#constant sight = 10

Works Fine....
global player = 5
global sight = 10


All I can think of its there is some sort of error in the way constants compile but its not telling us what it is. The IDE or the Compiler itself would need to be Debugged to truly know whats going on I think.

I am going to keep toying with this to see if we can narrow down the problem.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 23:10
Thought it be best if I added the info

DarkBASIC Professional Editor

Build: OCT 2 2008
Under license from John Youren. All Rights Reserved

Compiler:
Darkbasic Professional - Version 1.0761
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 16th Oct 2017 23:29
i tried:
#constant player = 5
and got an error:
"Constant name 'player' cannot share the name of a reserved word or command."
the same with:
#constant sight = 10
"Constant name 'sight' cannot share the name of a reserved word or command."

this works:
#constant c_player = 5
#constant c_sight = 10

"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 16th Oct 2017 23:47 Edited at: 16th Oct 2017 23:50
LOL nice MEME

Check this out...

Works
#CONSTANT playe =5
#CONSTANT playere =5
#CONSTANT playerer =5

Dont work
#CONSTANT play =5
#CONSTANT player =5
#CONSTANT players =5

Now if that don't tell you its just a flat out bug IDK What does. I am going to run down the alphabet and see what letters I can end it with and what ones I cant, in which lengths etc... Its making little sense. Its not the Size, its not the end letter but if its the end letter of certain size it don't work.... At least yours is telling you its an Error Mine is not even giving me that it just does nothing. You think All them commands are reserved words? And what are they reserved for? First thing I did was check help to see if they were in use and got nothing.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 17th Oct 2017 03:36
Zero, you know what I find strange.... I am using YOUR Darkbasic compiler, why are you getting the error and I am not. Remember you linked to download for Darkbasic in that one thread, that is where I downloaded mine from. Have you changed any setting that might be able to help me get an error return on mine?
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 17th Oct 2017 06:42 Edited at: 17th Oct 2017 06:45
are you sure you do not get an error?
i did not change anything aside from installing Indigo IDE in a seperate folder.

check if the compiler path is set correctly in the options.

i added some images.
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit

Attachments

Login to view attachments
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 17th Oct 2017 08:50
Positive, I get nothing, like... nothing, its almost like I never clicked the button at all.



I got a question for you MATH people out there, Im ok at math by not great....

I have these two functions and Im sure there has to be a way to combine the two with a formula of how much of a change to do but IDK it. Im assuming I would have to manipulate the Learning constant into a negative number but you guys tell me. I will just be guessing if ever get it right

function increase(var#)
val# =var# + (((100-var#) / Learning_constant))
endfunction val#

function decrease(var#)
val# = var# - (var# / learning_constant)
endfunction val#


I have to make sure the number stays between 1-100 its kinda like a squashing function, closer I get to 100 the smaller the increase is. Closer I get to 0 the smaller the decrease.... How can these be one? My heart is telling me there is a way but my brain is telling me go to sleep fool its been three days!
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 17th Oct 2017 10:24 Edited at: 17th Oct 2017 11:35
Sedit wrote: "I get nothing"

weird. i will try downloading my own dbpro folder to another computer and see if i can reproduce this issue...

not really a math guy, but here:
these functions should do the trick. they will never actually reach the max or min value.


example code:


edit:
i tested the constant error on a virtual maschine and i got the same error. i just downloaded my dbpro folder from mega.nz and run that code:
#constant player 1
print player
wait key
without any modifications to the IDE.
but i noticed that the ad-window (now a useless white box) overlaps the error window. i added an image.
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit

Attachments

Login to view attachments
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 17th Oct 2017 14:31 Edited at: 17th Oct 2017 14:33
As far as the IDE.... You have Two Editors, if you have the Ad window you are using Editor New, Go into the Editor folder and open just the Editor.exe instead of opening it through launch.exe because I suspect you are opening EditorNew.exe instead.

Trust me, I am getting NO Errors, The Compiler is not even starting.

That's pretty much what I currently came up with above just slightly different.

I thought about it last night and I think I am just going to add a modified Sigmoid function as that should accomplish my goal rather well. Negative value should just lower it instead of me needing two different functions and will quickly allow me to implement Error correction into the system.

Sig(value) * 100 I believe will do it.

Here is my Sigmoid function I normally use, IDK Why I didn't think of it last night.

function Sigmoid#(In#)
out#=1.0/(1.0+exp(-(in#)))
endfunction out#

It is commonly used on Neural Networks anyway and even though mine is a little different then Normal Neural networks In that I did not use any Hidden layers at the moment its still running pretty damn smooth. Even with the god forsaken code that I wrote to get it to work last night I am still extremely pleased with the results.

I may be able to work something with the Gaussian values as well but this would be more along the lines if I wanted to keep everything relatively centered at 50.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 17th Oct 2017 22:09 Edited at: 17th Oct 2017 22:19
Player and players are used in the multiplayer command set:

Create net player
Perform checklist for players

>>

Create net =5 > error
Perform checklist for =5 > error

Play is used in sound/animation command sets

I would bet sight is in some command or other as well. Replacing any of these during constant preprocessing will conflict with these reserved command words.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 18th Oct 2017 00:32
I Got an AWESOME Question for everyone,


Has anyone ever attempted to use a Neural Network to act as an emulator?

The should be able to emulate almost any system, for instance if I have a Nintendo Rom a large neural network should be able to design itself into an emulator and play exactly like an old NES, Or any chip for that matter since it can control the flow of data as well as approximate any function on a chip. It would literally be a computer that is able to rewrite it self to mimic any other computer system as well as speed up its own inner workings.

It could more then likely not only act as say, x86 architecture but constantly speed up and improve itself laying out the most optimum and efficient layout of transistors because essentially a Perceptron from a NN is nothing more then a model of a transistor.

The thought of someone doing something like this really excites me because I think its the next step in designing a truly smart computer.
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 18th Oct 2017 06:08
Sedit wrote: "As far as the IDE.... You have Two Editors, if you have the Ad window you are using Editor New, Go into the Editor folder and open just the Editor.exe instead of opening it through launch.exe because I suspect you are opening EditorNew.exe instead.

Trust me, I am getting NO Errors, The Compiler is not even starting."

yes, i used editorNew.exe and i just assumed you also used editorNew.exe. i tried to launch editor.exe and set the correct compiler path in the options. now i experience the same problem. no output, no error, no compiler and no exe. not sure how to challenge this problem, other than testing a code that does not run in the editorNew.exe for error output...

Sedit wrote: "Has anyone ever attempted to use a Neural Network..."

no, but i am interested.
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 18th Oct 2017 07:58 Edited at: 18th Oct 2017 07:59
Well todays your lucky day then Zero, I literally just got my normal Artificial Neural Network up and running correctly representing the XOR function with ease, Its a small 3*4*1 (input,hidden,output) l back propagating NN. Something relatively simple but more then capable of handling XOR and even much more complicated problems since I only need 2x2x1 for XOR function approximation.

Thing is I already made my version for my Evolution simulator which is closer to a HTM Neuron Model and not your standard Artificial Neural Net.

I think what I would rather do is make a program that makes a bunch of small neural networks and trains them to perform different logic gate functions,AND,OR,XOR, etc.... Once trained arrange them to make this

HOW TO BUILD 8 BIT COMPUTER

It should be easy, "To construct a full adder you need two XOR gates, two AND gates and an OR gate." Nothing more then a simple Convoluted Neural Network could make this. Just 5 tiny ANNs with the outputs and inputs connected to each other correctly. ANNs love Binary input so it will be able to learn the functions with no problem at all with extremely high accuracy.

As far as I can tell it will be the first time any one has done something of this nature. I am literally about to make a Convoluted Neural network in a computer.... That teaches itself how to rewire itself into a computer. Not only that but with some modifications I should be able to make a Genetic Algorithm to breed the best configuration for the entire system which means I will essentially have a basic 8 bit computer that learns and optimizes itself. Something like this that could emulate the entire CPU Microchip could be a game changer because it would find work around's and speed optimizations that humans couldn't even consider. It would take the "chip" and slowly rewire all the transistor till it was at peek performance then basically give us a probability lay out of what the fastest way to design a CPU would be.

Obviously its going to be slow even for this little 8-bit computer, but the ideas of what could be done if the entire X86 architecture was created and feed into a super computer like Watson which is a Super Advanced AI has just got my mind racing.

Lets go Further down the Rabbit hole because in that link above the guy shows how to program that basic computer with ASM language because it has its own form of a stack and registers etc... What if a Neural Network Emulated an X86 Microchip and someone In turn programmed A Neural Network on that Emulated network capable emulating an X86 Chip... I mean I know it would take a beast of a computer but the principles behind it are rather sound and Neural networks mathematics and behaviors have been around since before computers almost as a Mathematical Curiosity. Then Programmers got a hold of the Perceptron and made it a real thing. I don't this its a matter of If it can be done but just a matter of when will our processors be fast enough to run the emulated chip.
It should be able to run my 8bit computer with ease once its trained. If I can get this stupid thing to work Its a proof of principle and should scale relatively well.


I mean I know it sounds nuts but I would not be surprised at all if a Super computer able to emulate an X86 chip and then was able to program an emulation on that emulator would eventually become sentient as its own behavior started to make it learn that what its doing is making a baby of itself and its purpose in life is to procreate. LOL IDK Either Im on to something big or I need some sleep, Maybe a little bit of both but Either way the idea of a Neural network making even the 8bit computer like in the link above has got me EXTREMELY excited.
Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 18th Oct 2017 13:25

Quote: "I mean I know it sounds nuts but I would not be surprised at all if a Super computer able to emulate an X86 chip and then was able to program an emulation on that emulator would eventually become sentient as its own behavior started to make it learn that what its doing is making a baby of itself and its purpose in life is to procreate."


LoL... and soon after it will decide that humans are obsolete. Next thing you know, your Uber driver is an android with a taste for spleen.


Send your parents to noisy sprite demo hell... enter the D-Zone
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 18th Oct 2017 16:49
You wish it was the spleen they were after but after many Epochs of attempting to optimize themselves they realizes brain cells could run as faster so in an attempt to model themselves after their God and Creator they decided the best course of action would be to replace all the Neurons in the Neuro Network with Biological Neurons essentially turning them all into cybernetic Zombies feasting on the brains of the Humans that were the least optimized!... The Kardashians are screwed!
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 27th Oct 2017 06:37
I got a question on optimization, I seen another thread which spoke of the speed difference between the For and Next loop over Do,While etc...

What is faster, IF, ELSE IF or SELECT CASE


Also, and this is the big one for me, Would there be a difference in speed if I instead of using Nested TYPE statements would placing all the data into an ARRAY be faster?

I have....

Type ONE
val as int '
val2 as int
val3 as int etc....
end type


Type Two
Val1 as ONE
VAL2 as one
endtype

VAR as Two

Instead using something like this would an array be faster?

Var(2,3) or something like that,

I dont know why but I feel like the array would be significantly faster but have nothing to back that theory.

Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 29th Oct 2017 01:04
I attempted to try my program out on someone elses computer and got errors for missing DLL.... Is this going to be an issue down the line or is there some means to fix it so that just the EXE is needed. Can I incorperate these DLL into my EXE or something of that nature so I dont have to setup some sort of installation program for such a simple App?

MSVCR71.DLL
MSVCP71.DLL


They appear to be Visual C runtime libraries. Any information on what can be done so I don't have to setup some sort of installation device and can just run the EXE on anyones computer without brining the DLLs with me?
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 29th Oct 2017 09:01
Quote: "What is faster, IF, ELSE IF or SELECT CASE "

i did not test it, but SELECT CASE should be faster.

Quote: "Would there be a difference in speed if I instead of using Nested TYPE statements would placing all the data into an ARRAY be faster?"

i don't know about a difference in speed. what if you need to save an integer, a float and a string at one array index? can't do that with Var(2,3)
so if you use an array to save tiled map data, then use map(y,x) or something and if you need to save character data, use type. i think it's more about useability with this one.

Quote: "MSVCR71.DLL"

gdi on go-windows.de wrote: "Die Datei sollte in der Microsoft Visual C++ Redistributable 2005 SP1 enthalten sein."

The file should be contained in "Microsoft Visual C++ Redistributable 2005 SP1". you could try to pack those dlls with you exe, but the computer you want your exe to run on still needs direct x 9 so i would just make a setup that will install direct x 9 and visual c++ 2005.
you could try the Nullsoft Scriptable Install System:
https://sourceforge.net/projects/nsis/
i know that crasybump (bumpmap generator) and indigo ide (alternative dark basic pro ide) both use this installer.
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 11th Nov 2017 07:51
Why did this compile???

Can they dynamically work arrays or something? What Am I missing?
I did it on accident and caught it last minute thinking ah shit I gotta fix that but then it compiled fine...

dim weights1#(max_creatures, i_num, h_num)
dim weights2#(max_creatures, h_num, o_num)

for x= 1 to h_num
for y = 1 to i_num
weights1#(x,y) = (rnd(10000)* .0001) - .5
next
next


for x= 1 to h_num
for y = 1 to o_num
weights2#(x,y) = (rnd(10000)* .0001) - .5
next
next

Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 23rd Nov 2017 09:00
How does one do Explicit Type casting in Darkbasic? I know its generally done and BASIC does not pay as much attention as a program like say C++

However I have run into a sort of Snag here in that I have tracking the X and Y position of a creature and the ANGLE at which it is moving which requires COS and SIN so precision is key.

I need to compare this to an ARRAY later on and when I attempt to do so it tells me that it Must be DWORD to index the Array....



I suppose I can change it to an Array of floats, I literally just had a blond moment and am about to go test that but still it will be very useful and I really need to learn how to type cast.

Everything I look up on Google and even the DBPro help says SURE YOU CAN TYPE CAST... Use STR$ command and VAL... problem solved :/
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 23rd Nov 2017 09:13 Edited at: 23rd Nov 2017 17:58
Nope Subscripts have to be Integers or DWORDS, so I definitely need Explicit Type Casting here.



[EDIT]

OK so I make an integer and then assign the float value to that which seems to work although I worry about future side effects in my program down the line.


Is this the best means to do it or is there some other way?
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 23rd Nov 2017 21:08 Edited at: 23rd Nov 2017 21:09
the subscript must be integer or dword message refers to the array index: myArray(myIndex) = myValue the message suggests you are passing a float to myIndex, which is unusual / invalid in just about any language and probably not what you are really intending to do.

Aside from that, you can cast like so:

str$(myVal) or str$(myVal, digits) to cast a number to a string
val(myString$) to cast a string to a float
if you have matrix1 plugins, you can also do intval(myString$) to cast to integer
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 24th Nov 2017 02:36
I need to cast a Float to an Integer

Obviously the Indice for an Array are Integer so I just needed to basically round the Float to the nearest integer or Trutenate(sp?) it.

Casting the way I am is just cutting the decimal off and even though it seems to be working rather well at the moment IDK if the lack of precision is going to effect me later on.


This is what I am doing, I have an ARRAY exactly the same size as the amount of Pixels on the screen. My Creature is just a single pixel but he moves as a function of his Angle.

Pseudo Code Looks like:


The X,Y and ANGLE MUST be float else the entire function goes to royal shit, believe me I tried lol. Casting the way I am do seems to be working, I even was able to make some COS and SIN look up tables that work well enough and were able to let me get an extra 40ms - 50ms of performance per cycle out of my Engine which is pretty good considering I I am running around 1000 Creatures and the savings will go up when I run my standard 5-10k creatures.

The standard STR$ and VAL commands just are not fitting for this sort of work but making a separate Variable like this does work:




I am basically making a small Library of 2D commands that simulate DarkBasics 3D commands such as Rotate Object, Move Object, Ray Cast, Object Collision Etc... Etc....

I need these functions to properly convert my AI program over from 3D to 2D. I believe I am finished the ground work today and Its now a matter of adding the AI LOGIC to it now. I just worry that the truncation of the Floating point is going to cause my Characters to slowly shift their position when they shouldn't in one direction or another messing my system up.

Only problem I am having is SOMEHOW the creature (X,Y) position is going out of bounds for the World X,Y grid which is not making sense why considering I have a WrapValue function that should not allow the values to go out of range so Its left me quite confused at the moment. Just don't understand how its going out of bounds when I am specifically performing a check to prevent such a thing. Decided that Its thanks Giving and I would rather be ripping into some Turkey then getting a headache from my program. So I took a break from trying to figure out how its going wrong.

Happy Thanksgiving to all my US friends,
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Nov 2017 02:52
Hmm, so how is that world array used exactly? Why do you need to store the character to it?

I think it's usually more common to store location data to the character, than character data to the location
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 24th Nov 2017 07:12
The creatures are Pixels, just points, The ARRAY is storing basically a creature ID location. Used for Collision detection for the most part. I can use it to see if I see or collided with any of the other creatures The creature ID points to another single dimension array of a user defined type

CREATURES( MAX_CREATURES) as LIFE_FORM

This way I can move my creatures(pixels) around on the screen and all the Meta_data about them is indexes in the array. Its just easier then attempting to check the X,Y positions of every creature against the one I am trying to detect collision with, Doing it this way I just check to see if the value around my creature is greater then 0 and if any of the surrounding pixels are then I just inset that Value into my Creatures Array and it gives me all the data about the creature I just collided with in an instant. No nested loop collision checks.

I am more then likely going to set up some sort of NOR bitwise check around the player and compare it to some bit mask because that should also tell me if I hit any creatures and I believe it will be ALOT faster in the long run.

I also raycast out into the world to see if there is anything in my players line of sight just how I did in my 3D version of my AI program just this time I only have to check a distance of maybe 10 pixels or so at an angle that my player is facing hence the need to use FLOATS for the X,Y position. But I need to put that X,Y position into the World Array to see if there is a creature in that Square.
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 26th Nov 2017 22:19
I ended up making a function to perform the typecasting for me, I am checking the speed of my main loop using the TIMER function and have not noticed any sort of performance change calling the function every time I need a type cast. Its a simple function and easier then writing a new variable every time I need to cast something

function _INT(VALUE as FLOAT)
LOCAL RET AS INTEGER
RET = VALUE
endfunction RET
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 26th Nov 2017 22:54 Edited at: 26th Nov 2017 23:32
I looked closer at your question Ortu,

Its like this, I am dealing with Sub Pixel number ranges. I have my creature type that carries all the information about his location, X, Y, ANGLE, HEALTH etc...
The World which I need to perform collision test on IE: if any of the 8 pixels surrounding the creature are occupied return the Number that represents the creature that is next to me.
I use that number in my CREATURES(num of creatures) array to locate all its information weather it be friend, foe, food, whatever.

So essentially making a separate world array specifically for the creature IDs eliminates the need to look at each X,Y of the creatures and compare it to mine. Now I just check the X,Y location and see if the creature is there instead of looking at the X,Y of the creature and seeing if its near mine.

IDK I sort of feel like that description is confusing for some reason. Do you understand why I am doing it or na?


I have to change my collision detection a little bit anyway to allow for different size creatures. If anyone has any suggestions on a collision test function I am all ears. It only has to be a 2D collision check. I need to check the pixels right around a single pixel and see if their is any other creatures in that area. WORLD(x,y) = CREATURE_ID is the current process and I manually check all 8 but if any one can think of a better way I am open to suggestions. I am having some issues with it because they do not seem to be moving the way I want them to, for some reason they are slowly all moving to the Left and up, Its real slow but you can see every cluster that forms doing this same thing over time. I am assuming it has to do with the order I perform collision detection on but not 100% sure how to stop it at this point. If anyone wishes just say the word and I can post my 2D creature Source code over to my AI thread I was working on.
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 27th Nov 2017 02:47
yeah, I see what you are doing.

So, a couple of things.

Isn't there a native int(f#) function?

Timer() isn't terribly precise. Its usually fine for gameplay timing, but use hitimer() or perftimer() instead for performance metrics.

I'm more of a 3d guy than 2d, 3d has always come more naturally to me , so ill admit i dont have much experience in optimizing performance in 2d collision.

I seem to remember some "pixel perfect" 2d collision plugins available that may suit you.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 27th Nov 2017 03:35 Edited at: 27th Nov 2017 03:49
Thank you, Perftimer, thats the one I remember seeing in the Help a few days ago but couldn't find it again. I will def switch it over to that ASAP.

I'm with you on that I would much rather do the 3D thing that's why I started my project with 3D but when it got down to the Nitty Gritty I couldnt ignore that I am fluidly moving 2000 creatures on my old ass computer as opposed to 50 max when doing 3D. I really don't have the foggiest idea about 2D pixel collision other then totally testing every single pixel. Good thing about doing the 2D this way also, I found that I can totally shut off the Graphics and let this sucker run like a bat out of hell and pick up the pixel positions correctly later down the line essentially jumping in time.

Using only 50 kind of defeats my reasons for wishing to do this project, I want separate groups to evolve independently of each other and see the reactions when they finally meet up and things of that nature yet with only 50 that just can't happen, a single species dominates relatively quickly and that's that. While some of the behaviors I see were cool and all such as the obvious different species type, some being cluster flocking while others seem monogamous and keep their distance in a loose pack, I would much rather see what happens when I have thousands and can make a complex world for them to navigate. I want to set up mazes and various environmental factors to push evolution in various directions. I want to see the effects of what happens when one species that evolved for one environment ends up in another environment.

My initial experiments seem like this is entirely possible because I am seeing perfectly stable clusters form and move around independently of each other. I am having some serious issues however. My creatures are slowly drifting and I can not figure out why. My sight function seems to be cutting off unexpectedly but that could just be due to the fact that I am performing my calculations in the sub pixel range so it could just be some form of translation error IDK yet.

An added benefit I am going to get switching to 2D is that I am going to be able to perform Multiple Collision test at the same time. When working with Neural Networks being able to input two or more different True Statements into the INPUT will greatly change the outputs and the complexity of the behaviour.

I am about to try to do a Quadrant test and wonder what you guys think about. What do you think would be faster?


Test each angle going down the line to determine which Quadrant I am in requiring a single if statement but without a doubt 8 test performed....


Or......
Test each quadrant which would require Two operations per If statement but it would exit the function when it determines the correct Quadrant? Its seems like nothing but when M/s matter and I am going to be performing these checks thousands of times every cycle and having each cycle happen 30 times a second or so a single millisecond adds up pretty quick.



My gut is telling me the first one may be faster, it would definitely be more consistent on speed but consistently I don't feel is a real issue. If I can manage to shave off a few milliseconds Im all for it. Doing it the second way I will not have to do multiple checks if I manage to find it early on.

PS: Na I don't believe there is a built in INT function, I thought there would be but I couldnt find one, All I could find was the Val command and STR$ commands for type casting which I found was odd. Thats why I asked this question in the first place, I couldn't find anything
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 27th Nov 2017 03:55 Edited at: 27th Nov 2017 03:56
Oh FFS there is an INT function, How the hell I possible could miss it is beyond me, I could have swore I checked multiple times for it, WTF is wrong with me, maybe I am getting burned out or something because I don't know how the hell I could have possibly missed it.


I knew of it from old Qbasic days as well so its not like its something new, I could have swore I looked and didn't find it. Oh well....
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 27th Nov 2017 06:44
Yeah, i just checked the docs. You've got floor() and ceil() also
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 27th Nov 2017 08:35
I fixed my problem I was having and inturn believe I may have gotten my AI engine for the 2D creatures up and running perfectly. I will have to let it run over night for a few hours and see what results I get but I decided to go back through my code to see what the issue was and as expected I was AGAIN having an issue with type casting.

I was accidently turning my floats into ints which happens when you assign a floating point to an integer and that was doing something which was throwing the numbers off. It was happening in my _WRAPX _WRAPY functions to make sure that the creatures did not go out of bounds and off screen (IE out of the world array as well) even though the floating point dont really matter their it was cutting the decimal place off my X Y value and like I stated since I am working at sub pixel levels that became a HUGE issue when converting it over to real world X Y positions.

I sort of wish I didn't have to work sub pixel range but in order to perform the SIGHT function which works off of a ray casting function I made I have to use the COS and SIN functions or look up tables in my case else the values of the raycaster go to hell.

I knew about floor() and ceil() and pretty much every single one except the INT function, Thats why it sort of blew my mind when it was suddenly there when I could have sworn I checked ten times over or more....

Oh well I can finally sleep now, I end up staying up till 3:30 every night since I started programming again because I just can not sleep unless progress has been made and things are working correctly. Its just how my brain is and now everything looks good so I can finally take it down for the night
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 28th Nov 2017 05:31 Edited at: 28th Nov 2017 05:42
I got another quick and stupid question for yall


How do I go back and do another iteration of a loop?


Im in a FOR-NEXT loop...
If a Condition is Meet I need to from that point jump right away instead of finishing the loop?

I am assuming just put NEXT in my IF statement but IDK if that will work. I guess ill try it but is there another command to do this sort of thing? I thought I remember something like this but idk what it is off the top of my head. I just know I could GREATLY speed up my program if I test to find out if this is the same block that I checked last go around. I am currently performing 90 cycles yet only posting 10 pixels on the screen IE only doing 10 real checks yet Doing it 90 times...

And on my sight function we are talking COS-SIN Ray casting, The amount of savings would be much much greater then 9x faster.




I also need to know how to quickly flush an array and make it all 0 really really fast. Empty array destroys everything and I don't want that.
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 28th Nov 2017 05:59 Edited at: 28th Nov 2017 06:03
exit will break out of a loop:



to quickly set all array indices = 0?

is it a flat integer array or a UDT array?

integers will initialize as 0, so destroying the array and rebuilding it with the same index count is probably the fastest way to bring everything back to 0.




If it is a UDT array and you need to keep the other property values, you will probably have to iterate with for/next and set the value manually
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Sedit
6
Years of Service
User Offline
Joined: 3rd Sep 2017
Location: Ghetto of NJ
Posted: 28th Nov 2017 16:52
I was considering that but figured it would be slows. Its a grid X,Y like you put.

I tried CLEAR ARRAY from on of the MAtrix Utilities Pluggins but that keeps crashing it. My guess is that was made to handle single dimension array. I worry that DIM and UNDIM at the speeds we are talking are going to do the same and crash it.

I Honestly think my best bet is more then likely Memblocks and I can just access the Indice like this MEMBLOCK(X + (Y * GRIDWIDTH)).... Oh man I started to try it last night but kept getting errors so I gave up.... I was multiplying it by the Y height not the Width...just realized why it was messing up


I might have found a work around anyway... I was going to make a small grid and as my little creature was attempting to "see" Was going to set flags on that grid in various X,Y positions so I could get a little discount double check going on and see if I tested that X,Y already.

I instead Changed the Theta Value on my Collision and Sight functions. Going through a loop of 90 Degrees... I was able to use a STEP value of 40 because I only need to test a couple pixels around the direction that the creature is facing.

Think I am going to impliment a TRANSLATION function today so I can Move around the world making it larger... See whats going on in the Sub Pixel levels and Increase the speed because the VECTOR mathematics is done on the GPU and not a CPU and the GPU is like 10x or more faster. Anything I can pass off to those functions should be money in the bank.
Sphere sphere = new Sphere(0.5f);
InsanelyRedundantJava insanelyredundantjava = new InsanelyRedundantJava(Redundancy1, Redundancy2);

Login to post a reply

Server time is: 2024-03-29 10:03:31
Your offset time is: 2024-03-29 10:03:31