Posts: 108
Threads: 40
Joined: Aug 2001
hey what's up v1ctor?
do you use IRC anymore? 'cause I can't seem to find you....
anywho, I had to make a map editor for my game I'm making, I decided to make it in FB. Of course I am lazy, so I just built upon the tiny ptc example. But for some reason, my code crashes my computer. And it makes no sense. My first thought was that it was my bmp loader and tile drawer that were crashing. so I took out the calls to them... it still crashed... and so I took out all the ptc code... IT STILL CRASHED..... which brings me back to my subject of post....... AAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
COUNT HACKED BY RAZVEEE
RAZVEE IS A SCRIPT KIDDIE- hacker9
Posts: 108
Threads: 40
Joined: Aug 2001
Here's my code:
Code: ''
'' Map editor
''
DefInt A-Z
'$include: 'tinyptc.bi'
declare sub loadtileset ( file$ )
declare sub drawtile ( tileno as integer, x as integer, y as integer )
Const SCR_WIDTH = 320
Const SCR_HEIGHT = 200
Const SCR_SIZE = SCR_WIDTH * SCR_HEIGHT
Type bitmapheader
Identifier As String * 2
FileSize As uinteger
Reserved As uinteger
BitmapDataOffset As uinteger
BitmapHeaderSize As uinteger
bWidth As uinteger
bHeight As uinteger
Planes As ushort
BitsPerPixel As ushort
Compression As uinteger
BitmapDataSize As uinteger
HResolution As uinteger
VResolution As uinteger
Colors As uinteger
ImportantColors As uinteger
End Type
Type paletteentry
B As ubyte
G As ubyte
R As ubyte
U As ubyte
End Type
Dim buffer(0 To SCR_SIZE - 1) As Integer
redim shared tileset( 0 ) as integer
Dim tilesize As Integer
'if( ptc_open( "Agent Stealth - Map Editor", SCR_WIDTH, SCR_HEIGHT ) = 0 ) then
' end -1
' end if
'loadtileset "gfx\tileset01.bmp"
'drawtile 1, 100, 100
'ptc_update @buffer(0)
'do: loop until len(inkey$)
' ptc_close
Sub drawtile(tileno As Integer, x As Integer, y As Integer)
Dim scroff As Long, tileoff As Long
Dim idontknow As Integer
Dim i As Integer
off = x + y * SCREEN_WIDTH - SCREEN_WIDTH
idontknow = SCREEN_WIDTH - tilesize
For tileoff = (tileno - 1) * tilesize * tilesize To tileno * tilesize * tilesize
off = off + 1
If (off Mod tilesize) = 0 Then off = off + idontknow
buffer(off) = tileset(tileoff)
Next
End Sub
Sub loadtileset(file$)
Dim bh As bitmapheader
ReDim pal(1) As paletteentry
Dim i As Integer
Open file$ For Binary As #1
Get #1, , bh
ReDim pal(0 To bh.Colors - 1) As palentry
For i = 0 To bh.Colors - 1
Get #1, , pal(i)
Next i
tilesize = bh.bWidth
ReDim tileset(0 To bh.BitmapDataSize - 1) As Integer
For i = 0 To bh.BitmapDataSize - 1
Dim pixel As Byte
Get #1, , pixel
tileset(i) = (pal(pixel).R shl 16) or (pal(pixel).G shl 8) or pal(pixel).B
Next i
Close #1
End Sub
COUNT HACKED BY RAZVEEE
RAZVEE IS A SCRIPT KIDDIE- hacker9
Posts: 3,279
Threads: 170
Joined: Nov 2003
Set your BMP header Type to use Field = 1. Otherwise, it'll be the incorrect size. That's a start. Check out PTCXL, it has a fully working BMP loader. You can get it on freebasic.tk, as my FB site seems to be down again.
I'd knock on wood, but my desk is particle board.
Posts: 1,407
Threads: 117
Joined: Dec 2002
That's not the correct way of using TinyPTC. TinyPtc is hiding the main Windows event loop ina so called library, so you MUST be regularly calling ptc_update (so the event loop executes) or everything will crash.
I suggest to change
Code: 'ptc_update @buffer(0)
'do: loop until len(inkey$)
to
Code: do:ptc_update @buffer(0):sleep 1000:loop until len(inkey$)
The sleep 1000 is to avoid using a 100% of CPU in the refresh of an image that does'nt change...
Tinyptc was designed with demo coding in mind (zillions of frames per second), not to display a single frame and stop.
Antoni
Posts: 3,522
Threads: 189
Joined: Dec 2003
Not that it matters if you use zillions of frames, cause no omputer can handle it anyways.
Nothing matters as soon as you go above the screen refresh rate. It will no longer be visible.
And frame based movement is a bad idea anywas.
Posts: 1,407
Threads: 117
Joined: Dec 2002
Posts: 922
Threads: 15
Joined: Jun 2003
Yeah, this will work, see the comments :P
Code: ''
'' Map editor
''
DefInt A-Z
'$include: 'tinyptc.bi'
option explicit '' better when coding with loads of inc files :P
declare sub loadtileset ( file$ )
declare sub drawtile ( tileno as integer, x as integer, y as integer )
Const SCR_WIDTH = 320
Const SCR_HEIGHT = 200
Const SCR_SIZE = SCR_WIDTH * SCR_HEIGHT
Type bitmapheader field=1 '' tell FB to pack the struct
Identifier As ushort '' can't a string*, use the original C type
FileSize As uinteger
Reserved As uinteger
BitmapDataOffset As uinteger
BitmapHeaderSize As uinteger
bWidth As uinteger
bHeight As uinteger
Planes As ushort
BitsPerPixel As ushort
Compression As uinteger
BitmapDataSize As uinteger
HResolution As uinteger
VResolution As uinteger
Colors As uinteger
ImportantColors As uinteger
End Type
Type paletteentry
B As ubyte
G As ubyte
R As ubyte
U As ubyte
End Type
Dim shared buffer(0 To SCR_SIZE - 1) As Integer
redim shared tileset( 0 ) as integer
Dim shared tilesize As Integer
if( ptc_open( "Agent Stealth - Map Editor", SCR_WIDTH, SCR_HEIGHT ) = 0 ) then
end -1
end if
loadtileset "test.bmp"
drawtile 1, 10, 10
do
ptc_update @buffer(0)
sleep 100
loop until len(inkey$)
ptc_close
Sub drawtile(tileno As Integer, x As Integer, y As Integer)
Dim off As Long, tileoff As Long
Dim i As Integer, j as integer
off = y * SCR_WIDTH + x '' it was been called as SCREEN_WIDTH
tileoff = (tileno - 1) * tilesize * tilesize
for i = 0 to tilesize-1
For j = 0 to tilesize-1
buffer(off) = tileset(tileoff)
off = off + 1
tileoff = tileoff + 1
next j
off = off + SCR_WIDTH - tilesize '' ditto
Next i
End Sub
Sub loadtileset(file$)
Dim bh As bitmapheader
ReDim pal(1) As paletteentry
Dim i As Integer, x as integer, y as integer
Open file$ For Binary As #1
Get #1, , bh
ReDim pal(0 To bh.Colors - 1) As paletteentry
Get #1, , pal() '' you can read the whole array at once
tilesize = bh.bWidth
ReDim tileset(0 To bh.BitmapDataSize - 1) As Integer
for y = tilesize-1 to 0 step -1
i = y * bh.bWidth '' BMP's are stored upside down
for x = 0 to tilesize-1
Dim pixel As UByte '' 0..255, must to be unsigned
Get #1, , pixel
tileset(i) = (pal(pixel).R shl 16) or (pal(pixel).G shl 8) or pal(pixel).B
i = i + 1
next x
Next y
Close #1
End Sub
|