Author Topic: sw Part III  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
sw Part III
« on: February 21, 2013, 06:34:34 AM »
Deleted
« Last Edit: April 25, 2015, 05:10:50 AM by Peter »

Aurel

  • Guest
Re: sw Part III
« Reply #1 on: February 21, 2013, 08:32:30 AM »
Peter

I don't see any speed up in execution with sw.dll
then is with old sw.inc where is all function created.
Maybe is this because i use good old xp or simply my computer is to slow...

in program shock i have from 61-64 frames is this ok?
processor load is normal between 4 - 7%

Aurel

  • Guest
Re: sw Part III
« Reply #2 on: February 21, 2013, 12:10:39 PM »
You still don't answer me is there a speed up
between this with sw.dll as you say that is assembly and
sw.inc wth api...???
I don't see faster execution
or maybe i must compare them on different way ???

Aurel

  • Guest
Re: sw Part III
« Reply #3 on: February 21, 2013, 02:29:10 PM »
Yes i understand but you obviously don't understand what i want to ask you...
Where is proof that sw.dll execute faster same program then sw written as include file.
Do you get me now?

JRS

  • Guest
Re: sw Part III
« Reply #4 on: February 21, 2013, 03:47:58 PM »
It's a shame Peter doesn't have the static link files for USER32.DLL and other Windows resources then he could create one executable that doesn't rely on Windows at all.  8)

DLL phobics crack me up.

JRS

  • Guest
Re: sw Part III
« Reply #5 on: February 21, 2013, 05:20:01 PM »
Peter,

Good News!

I put a (SW) Wait(5) just before the SB WEND in the event loop and the CPU usage dropped to respectable levels without effecting game play. (even in a VirtualBox) If you can solve your OLE string restriction, I might take a second look at Simple Windows rather than writing a SDL extension module.

John

Update

I replace the Redraw() with Sync() and removed the Wait(5) and the game seems to run best and seems happier that it's being maintained within rather than a forced Wait(5) with every iteration of the event loop.
« Last Edit: February 21, 2013, 09:02:42 PM by JRS »

JRS

  • Guest
Re: sw Part III
« Reply #6 on: February 21, 2013, 10:43:09 PM »
Peter,

I solved the CPU issue with Simple Windows. Which finger of yours do I get to chop off?  :D

The issue was that SetFps(60) should only be done once and not every iteration of the event loop. I only use a sync in the event loop and CPU usage bounces around in the teens with smooth game control.

I also put the drawing to the background image in the init route which was another big CPU savings. I'm still looking at what really has to execute with each cycle of the loop and what doesn't. So far I'm becoming more optimistic Peter has a winner on his hands if he can just solve the string issue. (10th request)

May I give you a suggestion? When one of your users is having a problem, don't post new examples and ignore the issues and get piss off when pressed about it. I don't give up easy with anything I do so I took this as a personal challenge to wade through the mess.

John

PLEASE !!! solve the string passing issue for me.
« Last Edit: February 21, 2013, 11:39:40 PM by JRS »

Aurel

  • Guest
Re: sw Part III
« Reply #7 on: February 21, 2013, 11:21:58 PM »
Quote
You can believe or not, that is your thing.
I think you are planning to sell my libraries! This explains your nosiness.
And don't say, this crap needs nobody on the world!   

I don't have in plan to sell anything ,and don't be paranoid without reason.

JRS

  • Guest
Re: sw Part III
« Reply #8 on: February 22, 2013, 12:43:44 AM »
Here is the ScriptBasic version of SokoMouse with an obvious optimization pass. I'm sure there are other things that can be done to make it more efficient. I decided only to spin the arrows when a level is competed like the boxes and mouse does. This also reduced CPU usage. I now have the game running as smooth as silk with between 5 - 10% of CPU usage while running and doing any given task.

Peter may not call Simple Windows a game engine but it sure works really well with SB in that mode.

Code: OxygenBasic
  1. ' ScriptBasic SokoMouse
  2.  
  3. INCLUDE "sw.inc"
  4.  
  5. SUB Initialize
  6.   DrawBmp p1, 0, 0, 640, 480, 0
  7.   CALL ShowLevel
  8.   FOR bc = 0 TO 299
  9.     xBox[bc] = 0
  10.     yBox[bc] = 0
  11.     rBox[bc] = 0
  12.     zBox[bc] = 0
  13.     iBox[bc] = 0
  14.   NEXT
  15.   zR = 0
  16.   vR = 0
  17.   zA = 0
  18.   pHead = 3
  19.   Ready = 0
  20.   sl = 0
  21.   cV = 0
  22.   cR = 0
  23.   Steps = 0
  24.   RasReg = 0
  25.   KeyR = 0
  26.   KeyL = 0
  27.   KeyU = 0
  28.   KeyD = 0
  29.   BoxRas = 0
  30.   Turn = 1
  31.   zTurn = 0
  32. END SUB
  33.  
  34. SUB LoadMaps
  35.   LoadBytes "Maps/Map" & lev & "-1.bin", Map1
  36.   LoadBytes "Maps/Map" & lev & "-2.bin", Map2
  37.   LoadBytes "Maps/Map" & lev & "-3.bin", Map3
  38. END SUB  
  39.  
  40. SUB ShowLevel
  41.   Sprite s8, 480, 420, zA
  42.   Sprite s9, 576, 420, zA
  43.   IF lev < 10 THEN
  44.     BmpText fo, 520, 420, Nums[lev], 24, 24
  45.   ELSE
  46.     BmpText fo, 520, 420, STR(lev), 24, 24
  47.   END IF
  48.   vA += 1
  49.   IF vA = 8 THEN
  50.     vA = 0
  51.     zA = zA + 1
  52.     IF zA = 4 THEN zA = 0
  53.   END IF
  54. END SUB
  55.  
  56. SUB ShowMaps
  57.   FOR icx = 0 TO 14
  58.     FOR idx = 0 TO 19
  59.       ibx = icx * 20 + idx
  60.       IF ASC(Map1[ibx]) = 3 THEN Sprite s1, idx * 32, icx * 32, 3
  61.       IF ASC(Map3[ibx]) = 2 THEN Sprite s1, idx * 32, icx * 32, 2
  62.       IF ASC(Map2[ibx]) = 5 THEN Sprite s2, idx * 32, icx * 32, zR
  63.     NEXT
  64.   NEXT
  65.   vR += 1
  66.   IF vR = 10 THEN
  67.     vR = 0
  68.     zR += 1
  69.   END IF
  70.   IF zR = 4 THEN zR = 0
  71. END SUB
  72.  
  73. SUB FindHead
  74.   FOR icx = 0 TO 14
  75.     FOR idx = 0 TO 19
  76.       ibx = icx * 20 + idx
  77.       IF ASC(Map3[ibx]) = 6 THEN
  78.         xHead = idx * 32
  79.         yHead = icx * 32
  80.         rHead = 0
  81.         zHead = 0
  82.         EXIT SUB
  83.       END IF
  84.     NEXT
  85.   NEXT
  86. END SUB
  87.  
  88. SUB AllDone
  89.   IF Ready >= 1 THEN EXIT SUB
  90.   FOR icx = 0 TO 14
  91.     FOR idx = 0 TO 19
  92.       ibx = icx * 20 + idx
  93.       IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) <> 4 THEN
  94.         EXIT SUB
  95.       END IF
  96.     NEXT
  97.   NEXT
  98.   PlaySound w3
  99.   Ready = 2
  100.   RasReg = 1
  101.   Turn = 0
  102.   pHead = 0
  103.   rTurn = Rand(1, 2)
  104.   xTurn = xHead
  105.   yTurn = yHead
  106. END SUB
  107.  
  108. SUB TurnHead
  109.   IF Turn > 0 THEN EXIT SUB
  110.   IF rTurn = 1 THEN
  111.     Sprite s6, xTurn, yTurn, zTurn
  112.   ELSE IF rTurn = 2 THEN
  113.     Sprite s7, xTurn, yTurn, zTurn
  114.   END IF
  115.   zTurn = zTurn + 1
  116.   IF zTurn = 64 THEN zTurn = 0
  117. END SUB
  118.  
  119. SUB FlashBox
  120.   FOR icx = 0 TO 14
  121.     FOR idx = 0 TO 19
  122.       ibx = icx * 20 + idx
  123.       IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) = 4 THEN
  124.         Sprite s4, idx * 32, icx * 32, cR
  125.       END IF
  126.     NEXT
  127.   NEXT
  128.   cV += 1
  129.   IF cV = 10 THEN
  130.     cV = 0
  131.     cR += 1
  132.   END IF
  133.   IF cR = 4 THEN cR = 0
  134. END SUB
  135.  
  136. SUB ScanBoxes
  137.   IF BoxRas > 0 THEN EXIT SUB
  138.   FOR icx = 0 TO 14
  139.     FOR idx = 0 TO 19
  140.       ibx = icx * 20 + idx
  141.       IF ASC(Map3[ibx]) = 4 THEN
  142.         iBox[ibx] = 1
  143.         xBox[ibx] = idx * 32
  144.         yBox[ibx] = icx * 32
  145.         rBox[ibx] = 0
  146.       END IF
  147.     NEXT
  148.   NEXT
  149. END SUB
  150.  
  151. SUB ShowBoxes
  152.   FOR ibx = 20 TO 280
  153.     IF iBox[ibx] = 1 AND rBox[ibx] = 0 THEN
  154.       Sprite s1, xBox[ibx], yBox[ibx], 4
  155.     ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 1 THEN
  156.       xBox[ibx] = xBox[ibx] + 2
  157.       Sprite s1, xBox[ibx], yBox[ibx], 4
  158.       zBox[ibx] = zBox[ibx] + 2
  159.       IF zBox[ibx] = 32 THEN
  160.         zBox[ibx] = 0
  161.         iBox[ibx] = 0
  162.         icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
  163.         Map3[icx] = CHR(4)
  164.       END IF
  165.     ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 2 THEN
  166.       xBox[ibx] = xBox[ibx] - 2
  167.       Sprite s1, xBox[ibx], yBox[ibx], 4
  168.       zBox[ibx] = zBox[ibx] + 2
  169.       IF zBox[ibx] = 32 THEN
  170.         zBox[ibx] = 0
  171.         iBox[ibx] = 0
  172.         icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
  173.         Map3[icx] = CHR(4)
  174.       END IF
  175.     ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 3 THEN
  176.       yBox[ibx] = yBox[ibx] - 2
  177.       Sprite s1, xBox[ibx], yBox[ibx], 4
  178.       zBox[ibx] = zBox[ibx] + 2
  179.       IF zBox[ibx] = 32 THEN
  180.         zBox[ibx] = 0
  181.         iBox[ibx] = 0
  182.         icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
  183.         Map3[icx] = CHR(4)
  184.       END IF
  185.     ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 4 THEN
  186.       yBox[ibx] = yBox[ibx] + 2
  187.       Sprite s1, xBox[ibx], yBox[ibx], 4
  188.       zBox[ibx] = zBox[ibx] + 2
  189.       IF zBox[ibx] = 32 THEN
  190.         zBox[ibx] = 0
  191.         iBox[ibx] = 0
  192.         icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
  193.         Map3[icx] = CHR(4)
  194.       END IF
  195.     END IF
  196.   NEXT
  197. END SUB
  198.  
  199. SUB ScanHead
  200.   IF RasReg > 0 THEN EXIT SUB
  201.   idx = xHead / 32
  202.   icx = yHead / 32
  203.   ibx = icx * 20 + idx
  204.   IF ASC(Map3[ibx]) = 6 AND Key(vk_right) AND ASC(Map3[ibx + 1]) = 4 AND ASC(Map3[ibx + 2]) = 0 AND KeyR = 0 THEN
  205.     Map3[ibx] = CHR(0)
  206.     Map3[ibx + 1] = CHR(6)
  207.     rHead = 1
  208.     pHead = 1
  209.     BoxRas = 0
  210.     xBox[ibx + 1] = xHead + 32
  211.     yBox[ibx + 1] = yHead
  212.     rBox[ibx + 1] = 1
  213.     iBox[ibx + 1] = 1
  214.     Steps += 1
  215.     PlaySound w2
  216.   ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_left) AND ASC(Map3[ibx - 1]) = 4 AND ASC(Map3[ibx - 2]) = 0 AND KeyL = 0 THEN
  217.     Map3[ibx] = CHR(0)
  218.     Map3[ibx - 1] = CHR(6)
  219.     rHead = 2
  220.     pHead = 2
  221.     BoxRas = 0
  222.     xBox[ibx - 1] = xHead - 32
  223.     yBox[ibx - 1] = yHead
  224.     rBox[ibx - 1] = 2
  225.     iBox[ibx - 1] = 1
  226.     Steps += 1
  227.     PlaySound w2
  228.   ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_up) AND ASC(Map3[ibx - 20]) = 4 AND ASC(Map3[ibx - 40]) = 0 AND KeyU = 0 THEN
  229.     Map3[ibx] = CHR(0)
  230.     Map3[ibx - 20] = CHR(6)
  231.     rHead = 3
  232.     pHead = 3
  233.     BoxRas = 0
  234.     xBox[ibx - 20] = xHead
  235.     yBox[ibx - 20] = yHead - 32
  236.     rBox[ibx - 20] = 3
  237.     iBox[ibx - 20] = 1
  238.     Steps += 1
  239.     PlaySound w2
  240.   ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_down) AND ASC(Map3[ibx + 20]) = 4 AND ASC(Map3[ibx + 40]) = 0 AND KeyD = 0 THEN
  241.     Map3[ibx] = CHR(0)
  242.     Map3[ibx + 20] = CHR(6)
  243.     rHead = 4
  244.     pHead = 4
  245.     BoxRas = 0
  246.     xBox[ibx + 20] = xHead
  247.     yBox[ibx + 20] = yHead + 32
  248.     rBox[ibx + 20] = 4
  249.     iBox[ibx + 20] = 1
  250.     Steps += 1
  251.     PlaySound w2
  252.   ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_right) AND ASC(Map3[ibx + 1]) = 0 AND KeyR = 0 THEN
  253.     rHead = 1
  254.     pHead = 1
  255.     Map3[ibx] = CHR(0)
  256.     Map3[ibx + 1] = CHR(6)
  257.     Steps += 1
  258.     PlaySound w1
  259.   ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_left) AND ASC(Map3[ibx - 1]) = 0 AND KeyL = 0 THEN
  260.     rHead = 2
  261.     pHead = 2
  262.     Map3[ibx] = CHR(0)
  263.     Map3[ibx - 1] = CHR(6)
  264.     Steps += 1
  265.     PlaySound w1
  266.   ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_up) AND ASC(Map3[ibx - 20]) = 0 AND KeyU = 0 THEN
  267.     rHead = 3
  268.     pHead = 3
  269.     Map3[ibx] = CHR(0)
  270.     Map3[ibx - 20] = CHR(6)
  271.     Steps += 1
  272.     PlaySound w1
  273.   ELSE IF ASC(Map3[ibx]) = 6 AND Key(vk_down) AND ASC(Map3[ibx + 20]) = 0 AND KeyD = 0 THEN
  274.     rHead = 4
  275.     pHead = 4
  276.     Map3[ibx] = CHR(0)
  277.     Map3[ibx + 20] = CHR(6)
  278.     Steps += 1
  279.     PlaySound w1
  280.   ELSE
  281.     rHead = 0
  282.   END IF
  283. END SUB
  284.  
  285. SUB ShowHead
  286.   IF rHead = 0 AND pHead = 1 THEN
  287.     Sprite s3, xHead, yHead, 3
  288.   ELSE IF rHead = 0 AND pHead = 2 THEN
  289.     Sprite s3, xHead, yHead, 1
  290.   ELSE IF rHead = 0 AND pHead = 3 THEN
  291.     Sprite s3, xHead, yHead, 0
  292.   ELSE IF rHead = 0 AND pHead = 4 THEN
  293.     Sprite s3, xHead, yHead, 2
  294.   ELSE IF rHead = 1 THEN
  295.     xHead += 2
  296.     Sprite s3, xHead, yHead, 3
  297.     RasReg += 2
  298.     IF RasReg = 32 THEN
  299.       RasReg = 0
  300.       rHead = 0
  301.     END IF
  302.   ELSE IF rHead = 2 THEN
  303.     xHead -= 2
  304.     Sprite s3, xHead, yHead, 1
  305.     RasReg += 2
  306.     IF RasReg = 32 THEN
  307.       RasReg = 0
  308.       rHead = 0
  309.     END IF
  310.   ELSE IF rHead = 3 THEN
  311.     yHead -= 2
  312.     Sprite s3, xHead, yHead, 0
  313.     RasReg += 2
  314.     IF RasReg = 32 THEN
  315.       RasReg = 0
  316.       rHead = 0
  317.     END IF
  318.   ELSE IF rHead = 4 THEN
  319.     yHead += 2
  320.     Sprite s3, xHead, yHead, 2
  321.     RasReg += 2
  322.     IF RasReg = 32 THEN
  323.       RasReg = 0
  324.       rHead = 0
  325.     END IF
  326.   END IF
  327. END SUB
  328.  
  329. SUB MousePos
  330.   xPos = FIX(xMouse() / 32)
  331.   yPos = FIX(yMouse() / 32)
  332.   IF MouseButton() = 1 THEN
  333.     IF xPos = 15 AND yPos = 13 AND lev > 1 AND ButtonC = 0 THEN
  334.       lev -= 1
  335.       ButtonC = 1
  336.       PlaySound w4
  337.       Initialize
  338.       LoadMaps
  339.       FindHead
  340.       EXIT SUB
  341.     END IF
  342.   END IF
  343.   IF MouseButton() = 1 THEN
  344.     IF xPos = 18 AND yPos = 13 AND lev < 9 AND ButtonC = 0 THEN
  345.       lev += 1
  346.       ButtonC = 1
  347.       PlaySound w4
  348.       ' Sync
  349.      Initialize
  350.       LoadMaps
  351.       FindHead
  352.     END IF
  353.   END IF
  354.   IF MouseButton() = 0 THEN ButtonC = 0
  355. END SUB
  356.  
  357.  
  358. ' MAIN
  359.  
  360. Window 640, 480, 1
  361. SetCaption "ScriptBasic SokoMouse"
  362.  
  363. SetFps(60)
  364.  
  365. Q  = LoadBmp("SokoMedia/sokomouse.bmp", 1)
  366. p1 = LoadBmp("SokoMedia/Phantasie.bmp", 1)
  367. Fo = LoadBmp("SokoMedia/FontStrip.bmp", 96)
  368. s1 = LoadBmp("SokoMedia/SokoStrip.bmp", 5)
  369. s2 = LoadBmp("SokoMedia/RundStrip.bmp", 4)
  370. s3 = LoadBmp("SokoMedia/HeadStrip.bmp", 4)
  371. s4 = LoadBmp("SokoMedia/BoxsStrip.bmp", 4)
  372. s6 = LoadBmp("SokoMedia/HeadStripR.bmp", 64)
  373. s7 = LoadBmp("SokoMedia/HeadStripL.bmp", 64)
  374. s8 = LoadBmp("SokoMedia/ArroStripL.bmp", 4)
  375. s9 = LoadBmp("SokoMedia/ArroStripR.bmp", 4)
  376.  
  377. w1 = "SokoMedia/move.wav"
  378. w2 = "SokoMedia/push.wav"
  379. w3 = "SokoMedia/done.wav"
  380. w4 = "SokoMedia/clic.wav"
  381.  
  382. Nums[1] = "01"
  383. Nums[2] = "02"
  384. Nums[3] = "03"
  385. Nums[4] = "04"
  386. Nums[5] = "05"
  387. Nums[6] = "06"
  388. Nums[7] = "07"
  389. Nums[8] = "08"
  390. Nums[9] = "09"
  391.  
  392. Cls  0xCCCCCC
  393. Sprite Q, 180, 60, 0
  394. BmpText fo, 205, 32, "SOKOMOUSE", 24, 24
  395. BmpText fo, 170, 428, "PRESS ANY KEY", 24, 24
  396. WaitKey
  397.  
  398. lev = 1
  399. Initialize
  400. LoadMaps
  401. ShowLevel
  402. FindHead
  403.  
  404. WHILE Key(27) = 0
  405.   ShowMaps
  406.   IF sl THEN ShowLevel
  407.   ScanBoxes
  408.   ScanHead
  409.   ShowBoxes
  410.   ShowHead
  411.   FlashBox
  412.   AllDone
  413.   MousePos
  414.   TurnHead
  415.   IF Key(vk_space) THEN
  416.     BmpText fo, 64, 420, "Wait...", 24, 24
  417.     Initialize
  418.     LoadMaps
  419.     FindHead
  420.   END IF
  421.   BmpText fo, 200, 8, "SokoMouse", 24, 24
  422.   IF Ready = 2 THEN
  423.     BmpText fo, 64, 420, "Advance to the next level ...", 16, 16
  424.     sl = 1
  425.   END IF
  426.   BoxRas += 2
  427.   IF BoxRas = 32 THEN BoxRas = 0
  428.   IF Key(vk_right) = 0 THEN KeyR = 1
  429.   IF Key(vk_right)THEN KeyR = 0
  430.   IF Key(vk_left) = 0 THEN KeyL = 1
  431.   IF Key(vk_left) THEN KeyL = 0
  432.   IF Key(vk_up) = 0 THEN KeyU = 1
  433.   IF Key(vk_up) THEN KeyU = 0
  434.   IF Key(vk_down) = 0 THEN KeyD = 1
  435.   IF Key(vk_down) THEN KeyD = 0
  436.   Sync
  437. WEND
  438. CloseWindow
  439.  
« Last Edit: February 22, 2013, 12:53:57 AM by JRS »