News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

"Hello masm32", not a BOT, new member

Started by LordAdef, January 22, 2017, 09:42:24 AM

Previous topic - Next topic

LordAdef

Just checked, it´s the font that´s leaking memory.

I moved the code into WM_INITDIALOG, and also to WM_CREATE, but nothing happens in both places

LordAdef

Follow the zip code with prog4 fixed. No more memory leak, it´s steady at 3.132 bytes.
It was the font thing


hutch--


LordAdef

Quote from: hutch-- on February 05, 2017, 02:25:02 PM
Good you have chased it down.  :t

Thanks!

By the way, I´m doing these progs in increment to learn and improve piece by piece.
The idea is to make a re-creation of the Atari game "River Raid", in ascii. This scrolling experiment is the idea for the game´s map rolling down.

LordAdef

An update! And a world of questions....

So, still testing the waters... I made a temporary map of something closer to a River Raid level map.
The thing runs and stops when we reach the end of it.

There´s no game logic at all. I´m still trying things out.

I´m really on my own here, any help would be really appreciated!

I´m using the Window´s loop as my game loop.
I need a timer to control my game flow/speed. This was the best I could come out with. Any better solution?
Quoteinvoke GetTickCount  ;Timer
      mov tMyTick, eax
            .WHILE TRUE

                invoke GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                invoke DispatchMessage, ADDR msg
               
                ;=========================================================
                ;=============== MY GAME LOOP HERE!!!! ===================
                ;=========================================================
                ; My calling points here
                ; call pGame proc
                ; call pColisionDetection

                tTimer:                                                 ;Controlling speed                                     
                      invoke GetTickCount
                      sub eax, tMyTick
                      cmp eax, 40               ;waits x ticks
                      jb tTimer
                      invoke GetTickCount
                      mov tMyTick, eax

                invoke InvalidateRect,hwnd, ADDR mapRect, FALSE          ;All done, render:
            .ENDW

As an ascii game, I´m stuck with the WM_PAINT Msg, so I´m leaving all my rendering there.
(Man is that green A on screen. It´s gonna be the player´s boat.. or whatever)
Quote.ELSEIF uMsg==WM_PAINT
            ;invoke  GetTickCount                ;******** timing
            ;mov DebugTick, eax                  ;******** timing

        invoke BeginPaint,hWnd, ADDR ps
        mov    hdc,eax

        ;===== BK MAP ===============
        ;============================
        invoke SelectObject, hdc, Font1           ;select font
        RGB    255,255,255
        invoke SetTextColor,hdc, eax
        RGB    50,50,50
        invoke SetBkColor, hdc, eax
        invoke SetBkMode, hdc, OPAQUE
                                                  ;render map
                                                  ;(cHEIGHT-ArrayLineOffset)*cWIDTH...
                                                  ;...ArrayLineOffset increases until = cHEIGHT
        mov eax, cHEIGHT            ;(avoiding interdependancy)
        mov ebx, cWIDTH
        mov esi, offset Map         
        sub eax, ArrayLineOffset
        mov edi, 80                 ;loop counter
        mul ebx                     ;eax= lineOffset addr
        mov hitpoint.x, 80          ;loc x   
        add esi, eax                ;initial address to textout

        mov hitpoint.y, 1           ;loc of line 1

    @@:
        invoke TextOut,hdc,hitpoint.x,hitpoint.y, ADDR [esi], ebx
        add esi, ebx                ;next line

        add hitpoint.y, 10          ;y pos inc
        dec edi                     ;loop counter
        jnz @B
            ;invoke GetTickCount                         ;******** timing **********
            ;sub eax, DebugTick                          ;******** timing **********
            ;print str$(eax),13,10                       ;******** timing **********

        ;============================
        ;===== MAN ==================
        ;============================

        invoke SelectObject, hdc, Font2           ;select font
        RGB    0,255,0
        invoke SetTextColor,hdc, eax
        RGB    50,50,50
        invoke SetBkColor, hdc, eax
        invoke SetBkMode, hdc, TRANSPARENT
        invoke TextOut,hdc,0,600, ADDR Man, cWIDTH
        ;=====================================================================
        ;===== End of Map? ===================================================
        mov eax, cHEIGHT                        ;if it´s 0 then we reached
        cmp eax, ArrayLineOffset                ;       the top of the map
        jz LevelEnd

        inc ArrayLineOffset
        jmp PaintEnds
       
LevelEnd:                                             ;==Reached the end of Map. Level is over
        invoke EndPaint,hWnd, ADDR ps                 ;End Paint
        ret
PaintEnds:
        invoke EndPaint,hWnd, ADDR ps                 ;End Paint

.I need this map to be really optimized. Am I too bad? How can I make it faster
.I tried to time my code with the commented GetTickCount and related. I´m sure it´s not actually working as it should. Help...please

Lastly, this experiment has a major flaw: Every time one moves the mouse, Windows stops scrolling to do its things. I need to find a way to make it non stop. Honestly, I don´t know how

Cheers, Alex

hutch--

I would be inclined to use a timer as the loop you are using to get the delay is causing the problem with the mouse. I am rusty in this area but a multi-media timer used to have far better resolution. What processor are you using ? This may effect the thread timings depending on the core count.

LordAdef

Quote from: hutch-- on February 08, 2017, 06:09:39 PM
I would be inclined to use a timer as the loop you are using to get the delay is causing the problem with the mouse. I am rusty in this area but a multi-media timer used to have far better resolution. What processor are you using ? This may effect the thread timings depending on the core count.

Hi Hutch,
Win7 Professional 64bits
Intel Core i7-4790

LordAdef

Hutch, the mouse is not delaying, it´s actually halting the WM_PAINT.

hutch--

OK, hardware is fast enough with enough threads, when you set up a timer it is placed in another thread by the OS so you app should not have any lag in it.

LordAdef

Quote from: hutch-- on February 08, 2017, 07:28:57 PM
OK, hardware is fast enough with enough threads, when you set up a timer it is placed in another thread by the OS so you app should not have any lag in it.

Ok, I see what I can do!

LordAdef

#55
GOT IT!
At least for now that will do. I realised I was doing something stupid create an unnecessary loop hook in my timer. I´m using an .If.

Quoteinclude \masm32\include\winmm.inc
    includelib \masm32\lib\winmm.lib
...
It´s a timeGetTime in winmm.lib
Quoteinvoke timeGetTime 
                sub eax, MyTime
                .IF eax>=80
                    invoke InvalidateRect,hwnd, ADDR mapRect, FALSE          ;All done, render:
                    invoke timeGetTime                                       ;retrieve next Starting time
                    mov MyTime, eax
                .ENDIF


ps: Included the missing Level1.txt in the zip file

hutch--

 :t

This works fine on my Win10 64 bit.  :biggrin:

Interstingly I have not seen ascii animation for years. Once long ago I watched an ascii art version of star wars and you could follow what was happening.

LordAdef

Quote from: hutch-- on February 10, 2017, 04:57:37 AM
Interstingly I have not seen ascii animation for years. Once long ago I watched an ascii art version of star wars and you could follow what was happening.

Thanks Hutch. Yes, ascii animation is fun but has been out of the loop for a while. I thought it would be a nice project as a beginner not to have to deal with more complex graphics, an ascii little game could be acomplishable. In fact, it could even turn into a nice tutorial for newbies like me...

I will keep doing this project as I am, step by step, without jumping ahead of myself. Every little step teaches me something new, and that´s the goal.

LordAdef

A benchmark test between:

Quote.WHILE TRUE
   invoke PeekMessage, ADDR msg, NULL, 0, 0, PM_REMOVE
      .IF (eax != 0) ......
(using timeGetTime)

and
Quote.WHILE TRUE
      invoke GetMessage, ADDR msg, NULL, 0, 0; , PM_REMOVE
      .IF (eax != 0)......
using WM_TIMER

The 2 versions in the zip file.

timeGetTime vs TIMER (millisecs):

at 10:
timeGetTime   31-32            CPU: 11.88
TIMER      31-32            CPU: 11.66

at 40
timeGetTime   15-16   rare peaks: 31      CPU: 11.60
TIMER      15-16   rare peaks: 31      CPU: 6.85

at 80:
timeGetTime   15-16   rare peaks: 31      CPU: 11.88
TIMER      31-47   rare peaks: 16      CPU: 5.08

at 120:
timeGetTime   15-16   rare peaks: 31      CPU: 11.88
TIMER      31-47            CPU: 4.40





LordAdef

So, my map file was about 89.999 bytes and it´s too big, since I will need many.

I decided to optmize it.
With the code bellow I manage to turn the Level1.txt (89.999) into an array of 8.488 bytes.

It´s an array of pairs. Each pair reads "charValue", "lenght". So @@@@@@@@@@ gives 64,10.
The code works, but I have a stupid question I admit I couldn´t find the answer:

I wanted to put charValue into "bh", and the sum of chars into "bl". I thought if I pass "bx" to the array I had the right order. But it´s not... I manually inverted bh, bl, for bl, bh to have it right... What am I missing?

BX ->  BH, BL in this order, right?
I´m getting the other way around: BX-> BL, BH


QuoteThis should be in bh:
mov   bl, [esi + edi]                              ; the value for the new char in bl----------- Fills bl


This should be in bl:
add bh, 1                              ; it´s the same char, add sum in bh ------------------- sum in bh


Here I pass them to the array:
mov [eax], bx                        ; send the 2 bytes to dest array

Here is the complete procedure:
start:
      invoke pLoad, offset Filename
      inkey
      invoke ExitProcess, eax

pLoad proc, string:DWORD
            LOCAL       tLen :DWORD
            LOCAL    MapIndex:DWORD

          mov   esi, InputFile(string)                    ; esi is source   
          mov   tLen, ecx                                    ; lenght of file in tLen (returns in ecx)
    new:
          xor   ebx, ebx                                          ; bl= char  bh= char count
          mov   bl, [esi + edi]                              ; the value for the new char in bl----------- Fills bl
          mov   bh, 1                                              ; sum acumulator to 1
    same:   
          add    edi, 1                              ; add counter
          cmp   edi, tLen                 ; end of file?
          jz       done                              ; we are done
         
          cmp   bl, [esi + edi]                  ; comp char in bl with current
          jnz   notEqual

          ;it´s an equal char
          add bh, 1                              ; it´s the same char, add sum in bh ------------------- sum in bh
          jmp same                              ; jumps 'same'

    notEqual:                                    ; it´s a new sequence of the same new char
          mov eax, offset Map
          add eax, MapIndex
          mov [eax], bx                        ; send the 2 bytes to dest array
          add MapIndex, 2                  ; update dest array index
          jmp new                               ; 'new' sets the new char to bl

    done:
          free esi
          xor      edi, edi                                          ; edi is index

          printf ("Original size= %d ", tLen)
          print " ",13,10
          printf ("New size=  %d   ", MapIndex)
          print " ",13,10

      ret
pLoad endp   
end start


JJ, this f11 function in RichMasm is Fantastic!!