Medieval Dreams

Started by William, July 12, 2023, 20:29:04

Previous topic - Next topic

Derron

If you need "lookup tables" then instead of using "all:TList" you should consider using:
- an array if you simply store by "index" and do not delete/insert during game (as a "trimming" of an array will change the indices
- alternative to an array is brl.objectlist (TObjectlist) as it combines the functionality of a TList with arrays (so you could use "atIndex" faster than with a TList)
- a "TMap" (or variants) as they store "Key->value" pairs and thus the lookup for "key" can be way faster (binary tree search) than iterating through all elements like with the linked list (TList)

Regarding "index id" for your entities.
There are multiple ways to have a "unique" id ... eg mixing a timestamp and some random number - this works fine if you only create object ids every some milliseconds - or only a bunch of objects "per millisecond". This is how MongoDB creates object ids (first bits of the number are timestamp, 16 bits or so for the random number part).

In your own game engine you can of course simply have some kind of "(private) global lastID:Int" and a function GetNextID:Int()  (which increases the lastID value and returns the value). Means each generated entity uses "GetNextID()" and thus increases the value.
Pay attention to use something like "return bbAtomicAdd(lastID, 1)" in GetNextID() ... this function is defined in brl.threads and is there to have an "atomic addition" done to the variable without needing a mutex/lock.
You might think this is only useful when using "multithreading" ... but maybe you will add multiple threads later and then you forgot about your GetNextID() function ... et voila, multithreading issues incoming (multiple objects with same ID ...).


Ok ... so you now use "TMap" and store the key (integer) as string because TMap only allows objects as key.
Luckily TMap has a compagnon "TIntMap" which allows using integers as key ... 
Please use this to avoid creating new strings (objects) each time you do string(id). 
While Brucey added "hashes" to strings for faster lookup (I nagged long enough to improve string comparisons :P) a new string does not have the hash already available and thus comparison benefits from having these strings used over and over (eg the keys in the map itself benefit from it already).

TLDR: use TIntMap instead TMap. 


bye
Ron

William

-Added MaxGUI window with canvas graphics3d.

but it snags on windows or on linux with 2 windows open fps drops down to 29 or less on waitevent. is there an alternative i can use to waitevent or some other way of doing it for the window without without fps dropping that low?  i still get max fps on linux though.
im still interested in oldschool app/gamedev

William

-Added MaxGUI window with canvas graphics3d.

though it snags on windows or on linux with 2 windows open fps drops down to 29 or less on waitevent.
im still interested in oldschool app/gamedev

Derron

maybe you are using a laptop (remember that "trackpad" issue ...) and eg my HP elitebook had a refresh rate of 30 frames or so in Windows.

Means: if you sync to the refresh rate of your display ... then your fps can go down to 29 or whatever you see there. Please check how the refresh rate of your display is set up.


PS: If you want others to help you, then try to give either all needed details (how you approach something) or hand out a small (failing/exposing the issue) example code. This is especially if you do stuff which is "less common" - for me a maxgui + graphics3d thing is less common than using a brl.mod-module.


bye
Ron

Midimaster

In your mainloop I can see a Case EVENT_TIMERTICK, but I cannot find, that you really defined a timer:

Function SelectmaxguiEvents()
Select EventID()
Case EVENT_WINDOWCLOSE
exitapp=True
Case EVENT_TIMERTICK
RedrawGadget Canvas
Case EVENT_GADGETPAINT
UpdateCanvas(Canvas,camera)
End Select
End Function

Could it be, that you forgot to define the timer like this:

CreateTimer 60
This would mean, that the Refresh is only driven by other events and not by a continuously repeating tick.
...back from Egypt

William

#65
@Midimaster yes i missed that line. i was using https://www.syntaxbomb.com/minib3d/openb3dmax/msg347044656/#msg347044656 as reference as i was having difficulty, i did not know what made canvas work (and its already slipped my mind) hmm. edit: (createtimer seems to improve on windows not so severe drops even though fps is slower.) i had to add a condition executing different code because threading doesn't have the same behavior as Linux in the app that i could not thread the window (but i still can tinker with it) maybe its not a good idea to add a thread for that (application threads) but fps seems to not drop at all in linux (i thought there were supposed to be like 8 threads per core or per CPU but apparently there's thousands running.)

one thing i would like to amend is the white bar that appears at the bottom where the canvas doesn't cover the entire window space. @Derron  and others i appreciate your support, i will try to take your suggestions to code.
im still interested in oldschool app/gamedev

Midimaster

Quote from: William on February 26, 2024, 19:24:02one thing i would like to amend is the white bar that appears at the bottom where the canvas doesn't cover the entire window space
This is because you did not define all parameters of the CreateWindow() completely.
In this case the 7th parameter STYLE uses the default value WINDOW_DEFAULT, which is 15 or BIN 0000 1111.

Bit 4 (=8) switches On/Off the STATUS BAR. And this is the white bar you see at the bottom

So if you use 7 or BIN 0000 0111 you will get a window without white bar:

Local Window:TGadget=CreateWindow("MedievalDreams", winX, winY, Width, Height, Null, 7)

or better:

Const STYLE:Int= WINDOW_TITLEBAR | WINDOW_RESIZABLE | WINDOW_MENU
Local Window:TGadget=CreateWindow("MedievalDreams", winX, winY, Width, Height, Null, STYLE )
...back from Egypt

William

#67
hey i still have interest in completing my project here. here's where im at with it. i want to refactor (is that the term?) to import my bmx code in functions or something, i'm also trying to understand whether to use enet directly or should i stick with gnet or use a different netlib all together. Raknet is broke now because it didnt get updated with bmx and the new gcc compiler however im better off writing my own encryption for this.
im still interested in oldschool app/gamedev

William

im still interested in oldschool app/gamedev