maxmods / brl.mod Goto Github PK
View Code? Open in Web Editor NEWBlitzMax's BRL modules, patched and updated.
BlitzMax's BRL modules, patched and updated.
Create a simple graphical window.
SuperStrict
'Framework Brl.Retro
Import Brl.Graphics
Import Brl.GLMax2D
Import Pub.Win32
SetGraphicsDriver GLMax2DDriver()
Graphics 800,600
Function MyHook:Object( id:Int,data:Object,context:Object )
Local ev:TEvent=TEvent(data)
If Not ev Return data
Print "event: "+ev.id +" data="+ev.data
End Function
AddHook EmitEventHook,MyHook,Null,0
While Not (KeyHit(KEY_ESCAPE) Or AppTerminate())
DrawText "A = "+KeyDown(KEY_A), 0, 200
Flip
Cls
Wend
Hold "A" and Alt-Tab (needed, as clicking "somewhere into another window" does not emit suspend-events).
Keep holding "A" and Alt-Tab back into your window.
For BlitzMax "A" is no longer "down/hold" - as it flushes keys / mouse buttons.
Ok. If you now removed the flushkeys/flushmouse commands when suspending/resuming your app, you could release "A" while suspended but for blitzmax it is "down/hold" when alt-tabbing in again - and it keeps "hold" until you tap "A" again.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
#1 0x08499066 in __bb_pngloader_pngloader ()
#2 0x0815f127 in png_read_chunk_header (png_ptr=png_ptr@entry=0x8a003e8)
at /BlitzMax/mod/pub.mod/libpng.mod/pngrutil.c:162
#3 0x081507f0 in bmx_png_read_info (png_ptr=png_ptr@entry=0x8a003e8, info_ptr=info_ptr@entry=0x8a00770)
at /BlitzMax/mod/pub.mod/libpng.mod/pngread.c:108
#4 0x08154f0c in bmx_png_read_info (info_ptr=0x8a00770, png_ptr=0x8a003e8)
at /BlitzMax/mod/pub.mod/libpng.mod/pngread.c:941
#5 bmx_png_read_png (png_ptr=0x8a003e8, info_ptr=0x8a00770, transforms=17, params=0x0)
at /BlitzMax/mod/pub.mod/libpng.mod/pngread.c:947
#6 0x084995dd in brl_pngloader_LoadPixmapPNG ()
#7 0x0849a261 in _brl_pngloader_TPixmapLoaderPNG_LoadPixmap ()
#8 0x084a4e7b in brl_pixmap_LoadPixmap ()
#9 0x08488d2d in _brl_max2d_TImage_Load ()
#10 0x0848332a in brl_max2d_LoadImage ()
#11 0x08251c08 in _bb_TRegistrySpriteLoader_LoadSpritePackFromConfig ()
#12 0x08251914 in _bb_TRegistrySpriteLoader_LoadFromConfig ()
#13 0x081ce93d in _bb_TRegistryLoader_LoadSingleResourceFromXML ()
#14 0x081ce620 in _bb_TRegistryLoader_LoadResourcesFromXML ()
#15 0x081ce7a5 in _bb_TRegistryLoader_LoadSingleResourceFromXML ()
#16 0x081ce620 in _bb_TRegistryLoader_LoadResourcesFromXML ()
#17 0x081ce3f4 in _bb_TRegistryLoader_LoadFromXML ()
#18 0x082771f7 in _bb_TStationMapCollection_LoadMapFromXML ()
---Type <return> to continue, or q <return> to quit---
#19 0x08276011 in __bb_tests_base_stationmap ()
#20 0x081ca434 in _bb_main ()
#21 0x084c880a in __bb_appstub_appstub ()
#22 0x080517c4 in main (argc=1, argv=0xffffd074)
at /BlitzMax/mod/brl.mod/appstub.mod/appstub.linux.c:14
Seems latest commit is not liked by vanilla bmx.
Just a basic idea - as I try to improve the CPU consumption when having some heavy LUA-BlitzMax interaction:
Currently reflection.mod functions like FindMethod()
call string.ToLower()
on each comparison of "searched" vs "provided":
Method FindMethod:TMethod( name$ )
name=name.ToLower()
For Local t:TMethod=EachIn _methods
If t.Name().ToLower()=name Return t
Next
If _super Return _super.FindMethod( name )
End Method
We could either use TLowerString
there - or store two fields: the original _name:string and a _lowerStringName:string to at least save computation time in this scenario.
If we used Brucey's TLowerString
we somehow need to make sure it is made available to all - without importing it multiple times. How to add support for TLowerString
the most "compatible" way?
Just a small thought: is there a reason for all the "Special Maps" to not extend from TMap?
Think it would be handy to have fields:TMap = new TSpecialMap
.
In the current version (BCC 0.136, BMK 3.51, downloaded 2 days ago: 2023/04/05) in windows 10 this code runs into a bug:
Graphics 800,600,,,,600,200
Global currDriver:TGraphicsDriver= GetGraphicsDriver()
Print currDriver.ToString()
Repeat
Until AppTerminate()
______________
returns: OPENGL
no framework, no changes, only using the default settings of Blitzmax....
The window opens, the windows-Position uses the Y-value, but the X-value is ignored. So the window starts at the very left screen border (here: at 0,200)
I just replaced TPeristence's Field objectMap:TMap
to use TStringMap
.
When now loading in a savegame of my game I get one of the Reference not mapped yet
-errors thrown. Did I miss to change something?
Reverting back to TMap = new TMap
and loading is successful.
On startup, bbMemExtend is called with a null pointer, which crashes when bbMemCopy is called.
The fix is to only call bbMemCopy if the pointer is not null.
The wrong tree function is called in ValueForKey. It should be tree_search
instead of tree_map
.
Latest commit gives a compile error in x86 Debug under Windows. (non-debug x86 and both x64 appear to compile OK) bmk 3.24, bcc 0.94, MinGW 7.30
[ 1%] Processing:debugger_mt.stdio.bmx
Compile Error: Expecting expression but encountered ''
[c:/code/BlitzmaxNG730/mod/brl.mod/appstub.mod/deref_win32.bmx;43;0]
Build Error: failed to compile (-1) c:/code/BlitzmaxNG730/mod/brl.mod/appstub.mod/debugger_mt.stdio.bmx
Latest bmk/bcc, dxgraphics.mod does not compile:
[ 8%] Processing:d3d9graphics.bmx
[ 8%] Processing:source.bmx
Compile Error: Can't create instance of type TD3D9Graphics due to abstract Method TGraphics.Resize:Int(width:Int,height:Int).
[c:/code/BlitzmaxNG810/mod/brl.mod/dxgraphics.mod/d3d9graphics.bmx;162;0]
Build Error: failed to compile (-1) c:/code/BlitzmaxNG810/mod/brl.mod/dxgraphics.mod/d3d9graphics.bm
The "old"-function leads (sometimes) to a segfault within the For local handler:TRoomHandler = EachIn oldHandlers.Values()
-loop.
The other function does not segfault.
Function OLDonSaveGameLoad:int( triggerEvent:TEventBase )
TLogger.Log("TRoomHandlerCollection", "Savegame loaded - reassigning handlers", LOG_DEBUG | LOG_SAVELOAD)
local oldHandlers:TMap = GetInstance().handlers.Copy()
'request each handler to re-assign (the new instance of the handler)
'ATTENTION: this allows to handle this individually for each
' handler. The alternative (storing a "handle:string"-
' property in each handler) would lead to problems
' as soon as some offices have varying handlers
' or a handler wants to take care of multiply rooms
GetInstance().handlers.Clear()
For local handler:TRoomHandler = EachIn oldHandlers.Values()
if handler
handler.RegisterHandler()
print TTypeID.ForObject(handler).name() + " registered"
endif
Next
print "reregistered"
'inform the (new) handlers
For local handler:TRoomHandler = EachIn GetInstance().handlers.Values()
handler.onSaveGameLoad( triggerEvent )
Next
End Function
'called _after_ a game (and its data) got loaded
Function onSaveGameLoad:int( triggerEvent:TEventBase )
TLogger.Log("TRoomHandlerCollection", "Savegame loaded - reassigning handlers", LOG_DEBUG | LOG_SAVELOAD)
local oldHandlers:TRoomHandler[]
For local o:object = EachIn GetInstance().handlers.Values()
if TRoomHandler(o) then oldHandlers :+ [TRoomHandler(o)]
Next
'request each handler to re-assign (the new instance of the handler)
'ATTENTION: this allows to handle this individually for each
' handler. The alternative (storing a "handle:string"-
' property in each handler) would lead to problems
' as soon as some offices have varying handlers
' or a handler wants to take care of multiply rooms
GetInstance().handlers.Clear()
For local handler:TRoomHandler = EachIn oldHandlers
if handler
'this modifies "GetInstance().handlers"
handler.RegisterHandler()
print TTypeID.ForObject(handler).name() + " registered"
endif
Next
print "reregistered"
'inform the (new) handlers
For local handler:TRoomHandler = EachIn GetInstance().handlers.Values()
handler.onSaveGameLoad( triggerEvent )
Next
End Function
MarkCWM in the syntaxbomb.com forums just brought up an old thread (in which I replied...;-)
Grable enhanced brl.random to be threadsafe there.
Strict
Rem
bbdoc: Math/Random numbers
End Rem
Module BRL.Random
ModuleInfo "Version: 1.09"
ModuleInfo "Author: Mark Sibly, Floyd"
ModuleInfo "License: zlib/libpng"
ModuleInfo "Copyright: Blitz Research Ltd"
ModuleInfo "Modserver: BRL"
ModuleInfo "History: 1.09 [grable]"
ModuleInfo "History: Made seed==0 get seed from main thread (so threads start with main thread seed)"
ModuleInfo "History: 1.08 [grable]"
ModuleInfo "History: Added RndSeedMain() to get seed of main thread"
ModuleInfo "History: 1.07 [grable]"
ModuleInfo "History: Now thread-safe, each thread has its own seed"
ModuleInfo "History: 1.05 Release"
ModuleInfo "History: Fixed Rand() with negative min value bug"
Private
Const RND_A=48271,RND_M=2147483647,RND_Q=44488,RND_R=3399
?Not Threaded
Global rnd_state=$1234
?Threaded
Extern "C"
Function bbThreadAllocData:Int()
Function bbThreadSetData( index:Int, data:Int )
' Function bbThreadGetData:Int( index:Int )
Function bbThreadGetMain:Int Ptr()
Function bbThreadGetCurrent:Int Ptr()
EndExtern
' reimplemented to allow 0
Function bbThreadGetData:Int( index:Int)
' Return bbThreadGetCurrent()[2 + index]
Local slots:Int Ptr = bbThreadGetCurrent() + 2
Local rnd_state:Int = slots[index]
If rnd_state = 0 Then
slots[index] = rnd_state_init
Return rnd_state_init
EndIf
Return rnd_state
EndFunction
Function bbThreadGetMainData:Int( index:Int)
Return bbThreadGetMain()[2 + index]
EndFunction
Global rnd_state_init:Int = $1234
Global rnd_state_index:Int = bbThreadAllocData()
bbThreadSetData rnd_state_index, rnd_state_init
?
Public
Rem
bbdoc: Generate random float
returns: A random float in the range 0 (inclusive) to 1 (exclusive)
End Rem
Function RndFloat#()
?Threaded
Local rnd_state:Int = bbThreadGetData(rnd_state_index)
?
rnd_state=RND_A*(rnd_state Mod RND_Q)-RND_R*(rnd_state/RND_Q)
If rnd_state<0 rnd_state=rnd_state+RND_M
?Threaded
bbThreadSetData( rnd_state_index, rnd_state)
?
Return (rnd_state & $ffffff0) / 268435456# 'divide by 2^28
End Function
Rem
bbdoc: Generate random double
returns: A random double in the range 0 (inclusive) to 1 (exclusive)
End Rem
Function RndDouble!()
Const TWO27! = 134217728.0 '2 ^ 27
Const TWO29! = 536870912.0 '2 ^ 29
?Threaded
Local rnd_state:Int = bbThreadGetData(rnd_state_index)
?
rnd_state=RND_A*(rnd_state Mod RND_Q)-RND_R*(rnd_state/RND_Q)
If rnd_state<0 rnd_state=rnd_state+RND_M
Local r_hi! = rnd_state & $1ffffffc
rnd_state=RND_A*(rnd_state Mod RND_Q)-RND_R*(rnd_state/RND_Q)
If rnd_state<0 rnd_state=rnd_state+RND_M
Local r_lo! = rnd_state & $1ffffff8
?Threaded
bbThreadSetData( rnd_state_index, rnd_state)
?
Return (r_hi + r_lo/TWO27)/TWO29
End Function
Rem
bbdoc: Generate random double
returns: A random double in the range min (inclusive) to max (exclusive)
about:
The optional parameters allow you to use Rnd in 3 ways:
[ @Format | @Result
* &Rnd() | Random double in the range 0 (inclusive) to 1 (exclusive)
* &Rnd(_x_) | Random double in the range 0 (inclusive) to n (exclusive)
* &Rnd(_x,y_) | Random double in the range x (inclusive) to y (exclusive)
]
End Rem
Function Rnd!( min_value!=1,max_value!=0 )
If max_value>min_value Return RndDouble()*(max_value-min_value)+min_value
Return RndDouble()*(min_value-max_value)+max_value
End Function
Rem
bbdoc: Generate random integer
returns: A random integer in the range min (inclusive) to max (inclusive)
about:
The optional parameter allows you to use #Rand in 2 ways:
[ @Format | @Result
* &Rand(x) | Random integer in the range 1 to x (inclusive)
* &Rand(x,y) | Random integer in the range x to y (inclusive)
]
End Rem
Function Rand( min_value,max_value=1 )
Local range=max_value-min_value
If range>0 Return Int( RndDouble()*(1+range) )+min_value
Return Int( RndDouble()*(1-range) )+max_value
End Function
Rem
bbdoc: Set random number generator seed
End Rem
Function SeedRnd( seed )
?Not Threaded
rnd_state=seed & $7fffffff 'enforces rnd_state >= 0
?Threaded
Local rnd_state:Int = seed & $7fffffff 'enforces rnd_state >= 0
?
If rnd_state=0 Or rnd_state=RND_M rnd_state=$1234 'disallow 0 and M
?Threaded
If bbThreadGetCurrent() = bbThreadGetMain() Then rnd_state_init = rnd_state
bbThreadSetData( rnd_state_index, rnd_state)
?
End Function
Rem
bbdoc: Get random number generator seed
returns: The current random number generator seed
about: Use in conjunction with SeedRnd, RndSeed allows you to reproduce sequences of random
numbers.
End Rem
Function RndSeed()
?Not Threaded
Return rnd_state
?Threaded
Return bbThreadGetData(rnd_state_index)
?
End Function
?Threaded
Rem
bbdoc: Get random number generator seed of Main thread
returns: The current random number generator seed of the Main thread
about: Use in conjunction with SeedRnd, RndSeedMain allows you to reproduce sequences of random
numbers.
End Rem
Function RndSeedMain()
Return bbThreadGetMainData(rnd_state_index)
End Function
?
AddHook()
states to return an THook
object which you can use to delete it later on.
Either add a return t
to this function and a new param "hookObject:THook=Null" to RemoveHook()
or adjust the documentation (or even add an RemoveHookInstance(hook:THook)
to avoid the chain of parameters (in NG we could use overloaded functions).
The current implementation of brl.mod/system.mod does not open graphical dialogues on Linux. So when run from a graphical application it only outputs to the console windows. While this behaviour is okay for a console app, this is not very useful for the graphical ones.
To avoid this, one could replace
Method Notify( text$,serious )
WriteStdout text+"~r~n"
End Method
with
Method Notify( text$,serious )
system_ "xmessage -center ~q"+text+"~q"
End Method
and the likes.
I assume this is ok as long as it is run in an graphical environment. As it already utilizes "X11/..." things I am not sure if this creates trouble.
Also it might be a good thing to utilize:
https://sourceforge.net/projects/tinyfiledialogs/
which is a "small" c-project which wraps calls to "xmessage" (or another available command line tool) so we would not need to take care of what is installed. It also falls back to terminal-output if nothing "graphically" is available.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.