Skip to content

Commit

Permalink
Fix: enable O2 when building solution cause the do-nothing loop be op…
Browse files Browse the repository at this point in the history
…timized
  • Loading branch information
ppodds committed Dec 30, 2021
1 parent b74659a commit fe519a9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AAAAnimation/AAAAnimation.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<MASM Include="utils.asm" />
<MASM Include="transform.asm">
<FileType>Document</FileType>
</MASM>
Expand All @@ -128,6 +129,7 @@
<ClInclude Include="ffmpeg\stream_wrapper.h" />
<ClInclude Include="ffmpeg\video_decoder.h" />
<QtMoc Include="player\ascii_player_thread.h" />
<ClInclude Include="utils.h" />
<ClInclude Include="transform.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
6 changes: 6 additions & 0 deletions AAAAnimation/AAAAnimation.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@
<ClInclude Include="transform.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="utils.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<MASM Include="transform.asm">
<Filter>Source Files</Filter>
</MASM>
<MASM Include="utils.asm">
<Filter>Source Files</Filter>
</MASM>
</ItemGroup>
<ItemGroup>
<QtMoc Include="player\ascii_player_thread.h">
Expand Down
3 changes: 2 additions & 1 deletion AAAAnimation/player/ascii_player_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../ffmpeg/video_decoder.h"
#include "../console/console_controller.h"
#include "../transform.h"
#include "../utils.h"
#include <QThread>

AsciiPlayerThread::AsciiPlayerThread()
Expand Down Expand Up @@ -41,7 +42,7 @@ void AsciiPlayerThread::run()
transform(frame->data[0], arr, width, height, frame->linesize[0]);
// check time again
// wait until the proper time and play this frame
while (play_time - 150 > position); // 150ms offset to avoid drop too many frames
wait_until_smaller(play_time - 150, &position); // 150ms offset to avoid drop too many frames
std::cout << arr;
console_controller.top();
}
Expand Down
20 changes: 20 additions & 0 deletions AAAAnimation/utils.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
wait_until_smaller PROTO
; arguments
; xmm0: REAL4 a REAL4 variable need to be compared
; rdx: SQWORD PTR a SQWORD pointer which value be pointed would increase
; this procedure would block the thread until the condition is fulfilled
; Caution: it may cause the thread is blocked by a infinite loop
.CODE
wait_until_smaller PROC
push rbp
mov rbp, rsp
compare:
cvtsi2ss xmm1, SQWORD PTR [rdx] ; convert rdx to REAL4 type and store it in xmm1
comiss xmm0,xmm1 ; compare xmm0 with xmm1
jbe fufilled ; jump to fufilled if xmm0 <= xmm1
jmp compare ; jump to compare if xmm0 > xmm1
fufilled:
leave
ret
wait_until_smaller ENDP
END
3 changes: 3 additions & 0 deletions AAAAnimation/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once
#include <QThread>
extern "C" void wait_until_smaller(float, qint64*);

0 comments on commit fe519a9

Please sign in to comment.