refactoring
This commit is contained in:
parent
04da67a5e4
commit
4927f902d3
@ -68,11 +68,11 @@ int main(int argc, char *argv[])
|
||||
timer.play();
|
||||
while (1)
|
||||
{
|
||||
float row = timer.getRow();
|
||||
float row = float(timer.getRow()) / 10;
|
||||
if (!syncDevice->update(row)) break;
|
||||
|
||||
printf("%2.2f: %2.2f \n", row, track.getValue(row));
|
||||
Sleep(1000);
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -15,6 +15,7 @@ enum RemoteCommand {
|
||||
SET_KEY = 0,
|
||||
DELETE_KEY = 1,
|
||||
GET_TRACK = 2,
|
||||
SET_ROW = 3,
|
||||
};
|
||||
|
||||
#endif /* NETWORK_H */
|
||||
|
||||
38
sync/data.cpp
Normal file
38
sync/data.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "data.h"
|
||||
|
||||
using namespace sync;
|
||||
|
||||
size_t Data::getTrackIndex(const std::basic_string<TCHAR> &name)
|
||||
{
|
||||
TrackContainer::iterator iter = tracks.find(name);
|
||||
if (iter != tracks.end()) return int(iter->second);
|
||||
|
||||
size_t index = actualTracks.size();
|
||||
tracks[name] = index;
|
||||
actualTracks.push_back(new sync::Track);
|
||||
return index;
|
||||
}
|
||||
|
||||
Track &Data::getTrack(const std::basic_string<TCHAR> &name)
|
||||
{
|
||||
size_t index = getTrackIndex(name);
|
||||
assert(index >= 0);
|
||||
assert(index < int(actualTracks.size()));
|
||||
assert(NULL != actualTracks[index]);
|
||||
return *actualTracks[index];
|
||||
}
|
||||
|
||||
Track &Data::getTrack(size_t track)
|
||||
{
|
||||
assert(track >= 0);
|
||||
assert(track < tracks.size());
|
||||
|
||||
sync::Data::TrackContainer::iterator trackIter = tracks.begin();
|
||||
for (size_t currTrack = 0; currTrack < track; ++currTrack, ++trackIter);
|
||||
return *actualTracks[trackIter->second];
|
||||
}
|
||||
|
||||
size_t Data::getTrackCount() const
|
||||
{
|
||||
return tracks.size();
|
||||
}
|
||||
@ -10,7 +10,8 @@ public:
|
||||
ClientDevice(const std::string &baseName, SOCKET serverSocket, Timer &timer) :
|
||||
baseName(baseName),
|
||||
timer(timer),
|
||||
serverSocket(serverSocket)
|
||||
serverSocket(serverSocket),
|
||||
serverRow(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -24,12 +25,12 @@ private:
|
||||
sync::Data syncData;
|
||||
Timer &timer;
|
||||
|
||||
int serverRow;
|
||||
SOCKET serverSocket;
|
||||
};
|
||||
|
||||
ClientDevice::~ClientDevice()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Track &ClientDevice::getTrack(const std::string &trackName)
|
||||
@ -94,7 +95,7 @@ bool ClientDevice::update(float row)
|
||||
int track, row;
|
||||
recv(serverSocket, (char*)&track, sizeof(int), 0);
|
||||
recv(serverSocket, (char*)&row, sizeof(int), 0);
|
||||
printf("delete: %d,%d = %f\n", track, row);
|
||||
printf("delete: %d,%d\n", track, row);
|
||||
|
||||
sync::Track &t = syncData.getTrack(track);
|
||||
t.deleteKeyFrame(row);
|
||||
@ -106,6 +107,19 @@ bool ClientDevice::update(float row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (timer.isPlaying())
|
||||
{
|
||||
int newServerRow = int(floor(row));
|
||||
if (serverRow != newServerRow)
|
||||
{
|
||||
unsigned char cmd = SET_ROW;
|
||||
send(serverSocket, (char*)&cmd, 1, 0);
|
||||
send(serverSocket, (char*)&newServerRow, sizeof(int), 0);
|
||||
serverRow = newServerRow;
|
||||
}
|
||||
}
|
||||
|
||||
return !done;
|
||||
}
|
||||
|
||||
|
||||
@ -318,7 +318,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
|
||||
ATOM mainClass = registerMainWindowClass(hInstance);
|
||||
ATOM trackViewClass = registerTrackViewWindowClass(hInstance);
|
||||
if(!mainClass || ! trackViewClass)
|
||||
if (!mainClass || !trackViewClass)
|
||||
{
|
||||
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"), MB_ICONEXCLAMATION | MB_OK);
|
||||
return 0;
|
||||
@ -327,7 +327,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
trackView = new TrackView();
|
||||
trackView->setSyncData(&syncData);
|
||||
|
||||
// Step 2: Creating the Window
|
||||
HWND hwnd = CreateWindowEx(
|
||||
0,
|
||||
mainWindowClassName,
|
||||
@ -405,42 +404,52 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
switch (cmd)
|
||||
{
|
||||
case GET_TRACK:
|
||||
size_t clientIndex = 0;
|
||||
int ret = recv(clientSocket, (char*)&clientIndex, sizeof(int), 0);
|
||||
printf("client index: %d\n", clientIndex);
|
||||
|
||||
// get len
|
||||
int str_len = 0;
|
||||
ret = recv(clientSocket, (char*)&str_len, sizeof(int), 0);
|
||||
|
||||
// int clientAddr = 0;
|
||||
// int ret = recv(clientSocket, (char*)&clientAddr, sizeof(int), 0);
|
||||
|
||||
// get string
|
||||
std::string trackName;
|
||||
trackName.resize(str_len);
|
||||
recv(clientSocket, &trackName[0], str_len, 0);
|
||||
|
||||
// find track
|
||||
size_t serverIndex = syncData.getTrackIndex(trackName.c_str());
|
||||
printf("name: \"%s\"\n", trackName.c_str());
|
||||
|
||||
// setup remap
|
||||
syncData.clientRemap[serverIndex] = clientIndex;
|
||||
|
||||
const sync::Track &track = *syncData.actualTracks[serverIndex];
|
||||
|
||||
sync::Track::KeyFrameContainer::const_iterator it;
|
||||
for (it = track.keyFrames.begin(); it != track.keyFrames.end(); ++it)
|
||||
{
|
||||
int row = int(it->first);
|
||||
const sync::Track::KeyFrame &key = it->second;
|
||||
syncData.sendSetKeyCommand(int(serverIndex), row, key);
|
||||
size_t clientIndex = 0;
|
||||
int ret = recv(clientSocket, (char*)&clientIndex, sizeof(int), 0);
|
||||
printf("client index: %d\n", clientIndex);
|
||||
|
||||
// get len
|
||||
int str_len = 0;
|
||||
ret = recv(clientSocket, (char*)&str_len, sizeof(int), 0);
|
||||
|
||||
// int clientAddr = 0;
|
||||
// int ret = recv(clientSocket, (char*)&clientAddr, sizeof(int), 0);
|
||||
|
||||
// get string
|
||||
std::string trackName;
|
||||
trackName.resize(str_len);
|
||||
recv(clientSocket, &trackName[0], str_len, 0);
|
||||
|
||||
// find track
|
||||
size_t serverIndex = syncData.getTrackIndex(trackName.c_str());
|
||||
printf("name: \"%s\"\n", trackName.c_str());
|
||||
|
||||
// setup remap
|
||||
syncData.clientRemap[serverIndex] = clientIndex;
|
||||
|
||||
const sync::Track &track = *syncData.actualTracks[serverIndex];
|
||||
|
||||
sync::Track::KeyFrameContainer::const_iterator it;
|
||||
for (it = track.keyFrames.begin(); it != track.keyFrames.end(); ++it)
|
||||
{
|
||||
int row = int(it->first);
|
||||
const sync::Track::KeyFrame &key = it->second;
|
||||
syncData.sendSetKeyCommand(int(serverIndex), row, key);
|
||||
}
|
||||
|
||||
InvalidateRect(trackViewWin, NULL, FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case SET_ROW:
|
||||
{
|
||||
int newRow = 0;
|
||||
int ret = recv(clientSocket, (char*)&newRow, sizeof(int), 0);
|
||||
printf("new row: %d\n", newRow);
|
||||
trackView->setEditRow(newRow);
|
||||
}
|
||||
|
||||
InvalidateRect(trackViewWin, NULL, FALSE);
|
||||
break;
|
||||
// case SOMETHING_ELSE:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,10 +222,6 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\syncdata.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\synceditdata.h"
|
||||
>
|
||||
</File>
|
||||
|
||||
@ -25,6 +25,8 @@ public:
|
||||
int getRows() const { return rows; }
|
||||
void editBiasValue(float amount);
|
||||
|
||||
void setEditRow(int newEditRow);
|
||||
|
||||
private:
|
||||
// some nasty hackery to forward the window messages
|
||||
friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
@ -45,8 +47,6 @@ private:
|
||||
void editCut();
|
||||
void editPaste();
|
||||
|
||||
// the window procedure
|
||||
|
||||
void paintTracks(HDC hdc, RECT rcTracks);
|
||||
void paintTopMargin(HDC hdc, RECT rcTracks);
|
||||
|
||||
@ -102,7 +102,6 @@ private:
|
||||
InvalidateRect(hwnd, &rect, FALSE);
|
||||
}
|
||||
|
||||
void setEditRow(int newEditRow);
|
||||
void setEditTrack(int newEditTrack);
|
||||
|
||||
int getScreenY(int row);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user