Last active
December 27, 2015 12:59
-
-
Save hjpbarcelos/7330186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gerenciar_canvas.cpp - Generated by Visual Multi-Thread Win32 */ | |
#include "AppObjects.h" | |
#include "global.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <tchar.h> | |
#include <conio.h> | |
#include <windows.h> | |
#include "graphics2.h" | |
extern polygon poligonos[32]; | |
extern bool screen_cleared; | |
extern bool isRunning; | |
DWORD WINAPI thread_gerenciar_canvas(LPVOID lpParameter); | |
DWORD WINAPI thread_gerenciar_canvas(LPVOID lpParameter) | |
{ | |
printf("CANVAS EXECUTANDO\n"); | |
bool allReady; | |
while(isRunning){ | |
EnterCriticalSection(&gerenciador); | |
if(!screen_cleared){ | |
printf("TELA SUJA\n"); | |
allReady = true; | |
for(int i=0;i<32;i++){ | |
if(poligonos[i].enabled){ | |
if(!poligonos[i].ready){ | |
printf("POLIGONO %d NÃO ESTÁ PRONTO", i); | |
allReady = false; | |
Sleep(500); | |
} | |
} | |
} | |
if(allReady){ | |
printf("TODOS PRONTOS\n"); | |
Sleep(500); | |
cleardevice(); | |
screen_cleared=true; | |
} | |
} else { | |
printf("TELA LIMPA"); | |
} | |
LeaveCriticalSection(&gerenciador); | |
} | |
printf("WTF"); | |
TerminateThread(gerenciar_canvas, false); | |
TerminateThread(gerenciar_canvas, false); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gerenciar_figura.cpp - Generated by Visual Multi-Thread Win32 */ | |
#include "AppObjects.h" | |
#include "global.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <tchar.h> | |
#include <conio.h> | |
#include <windows.h> | |
#include "graphics2.h" | |
#include "global.h" | |
extern polygon poligonos[32]; | |
extern bool screen_cleared; | |
extern bool isRunning; | |
DWORD WINAPI thread_gerenciar_figura(LPVOID tn); | |
DWORD WINAPI thread_gerenciar_figura(LPVOID tn) | |
{ | |
int thread_num = (int) tn; | |
int i; | |
poligonos[thread_num].type=SOLID_FILL; | |
poligonos[thread_num].color=15; | |
setfillstyle(poligonos[thread_num].type, poligonos[thread_num].color); | |
i=0; | |
if(poligonos[thread_num].enabled){ | |
printf("THREAD %d CRIADA\n",thread_num); | |
} else { | |
printf("FAIL"); | |
} | |
while(poligonos[thread_num].enabled){ | |
EnterCriticalSection(&gerenciador); | |
Sleep(500); | |
printf("THREAD %d EXECUTADA\n", thread_num); | |
if(screen_cleared){ | |
Sleep(100); | |
printf("THREAD %d MOVIMENTADA\n", thread_num); | |
rectangle(10+i,10+i, 50,30); | |
i++; | |
screen_cleared=false; | |
poligonos[thread_num].ready=true; | |
} | |
LeaveCriticalSection(&gerenciador); | |
} | |
printf("THREAD %d TERMINADA\n",thread_num); | |
TerminateThread(gerenciar_figura, false); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "global.h" | |
polygon poligonos[32]; | |
bool screen_cleared; | |
bool isRunning; | |
// outras coisas... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef GLOBAL_H | |
#define GLOBAL_H | |
struct polygon | |
{ | |
int x, y, width, height, speed, direction, type, color; | |
bool enabled, ready; | |
HANDLE tHandle; | |
DWORD tId; | |
}; | |
extern polygon poligonos[32]; | |
extern bool screen_cleared; | |
extern bool isRunning; | |
#endif /* APPOBJECTS_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* input_usuario.cpp - Generated by Visual Multi-Thread Win32 */ | |
#include "AppObjects.h" | |
#include "global.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <tchar.h> | |
#include <conio.h> | |
#include <windows.h> | |
extern polygon poligonos[32]; | |
extern bool screen_cleared; | |
extern bool isRunning; | |
DWORD WINAPI thread_input_usuario(LPVOID lpParameter); | |
extern DWORD WINAPI thread_gerenciar_figura(LPVOID tn); | |
DWORD WINAPI thread_input_usuario(LPVOID lpParameter) | |
{ | |
int anterior = 0, atual=0; | |
extern polygon poligonos[32]; | |
extern bool isRunning; | |
while(GetKeyState('Q')>=0) | |
{ | |
//Sleep(500); | |
atual = GetKeyState('T'); | |
if(atual!=anterior && (atual==0 || atual==1)) | |
{ | |
printf("%d %d\n",atual, anterior); | |
anterior=atual; | |
printf("NEW POLYGON CREATED\n"); | |
Sleep(1000); | |
for(int i=0;i<32;i++) | |
{ | |
if(!poligonos[i].enabled) | |
{ | |
poligonos[i].enabled=true; | |
gerenciar_figura = CreateThread(0, 0,(LPTHREAD_START_ROUTINE) thread_gerenciar_figura, (LPVOID) i, 0, &poligonos[i].tId); | |
poligonos[i].tHandle=gerenciar_figura; | |
break; | |
} | |
else | |
{ | |
} | |
} | |
} | |
else | |
{ | |
} | |
} | |
isRunning = false; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* main.cpp - Generated by Visual Multi-Thread Win32 */ | |
#include "AppObjects.h" | |
#include "global.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <tchar.h> | |
#include <conio.h> | |
#include <windows.h> | |
#include <iostream> | |
#include "graphics2.h" | |
extern polygon poligonos[32]; | |
extern bool screen_cleared; | |
extern bool isRunning; | |
extern DWORD WINAPI thread_gerenciar_canvas(LPVOID lpParameter); | |
extern DWORD WINAPI thread_input_usuario(LPVOID lpParameter); | |
void main(void); | |
void main(void) | |
{ | |
int GraphDriver = 0,GraphMode = 0; | |
screen_cleared = true; | |
isRunning = true; | |
initgraph(&GraphDriver, &GraphMode, "", 640, 480); | |
for(int i=0;i<32;i++){ | |
poligonos[i].enabled=false; | |
} | |
InitializeCriticalSection(&gerenciador); | |
input_usuario = CreateThread(0, 0,(LPTHREAD_START_ROUTINE) thread_input_usuario, 0, 0, 0); | |
gerenciar_canvas = CreateThread(0, 0,(LPTHREAD_START_ROUTINE) thread_gerenciar_canvas, 0, 0, 0); | |
WaitForSingleObject(input_usuario, INFINITE); | |
WaitForSingleObject(gerenciar_canvas, INFINITE); | |
DeleteCriticalSection(&gerenciador); | |
printf("out"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment