From 8a0024415eba0fef060891aed022a02cd2384743 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sat, 27 Oct 2012 17:05:08 +0200 Subject: [PATCH] WIP on fixing up TrackerView --- ogl_editor/src/Editor.c | 19 +++++++------ ogl_editor/src/RemoteConnection.c | 8 +++--- ogl_editor/src/RemoteConnection.h | 2 +- ogl_editor/src/TrackView.c | 59 ++++++++++++++++++++++++--------------- ogl_editor/src/TrackView.h | 4 ++- 5 files changed, 54 insertions(+), 38 deletions(-) diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c index c2f67e5..a030ec1 100644 --- a/ogl_editor/src/Editor.c +++ b/ogl_editor/src/Editor.c @@ -24,10 +24,18 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +typedef struct TrackInfo +{ + bool folded; +} TrackInfo; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + typedef struct EditorData { struct sync_data syncData; TrackViewInfo trackViewInfo; + TrackInfo trackInfo; int trackOrder[8192]; int orderCount; @@ -38,7 +46,6 @@ static EditorData s_editorData; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static uint64_t fontIds[2]; -int clientIndex = 0; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -65,7 +72,7 @@ void Editor_update() { Emgui_begin(); - TrackView_render(&s_editorData.trackViewInfo); + TrackView_render(&s_editorData.trackViewInfo, &s_editorData.syncData); Emgui_end(); } @@ -139,18 +146,12 @@ static void processCommands() serverIndex = createTrack(&s_editorData, trackName); // setup remap and send the keyframes to the demo - RemoteConnection_mapTrackName(trackName, clientIndex++); + RemoteConnection_mapTrackName(trackName); RemoteConnection_sendKeyFrames(trackName, s_editorData.syncData.tracks[serverIndex]); - // send key-frames - //t = doc->tracks[serverIndex]; - //for (i = 0; i < (int)t->num_keys; ++i) - // doc->clientSocket.sendSetKeyCommand(trackName, t->keys[i]); - break; } - case SET_ROW: { RemoteConnection_recv((char*)&newRow, sizeof(int), 0); diff --git a/ogl_editor/src/RemoteConnection.c b/ogl_editor/src/RemoteConnection.c index c37a72a..0210c10 100644 --- a/ogl_editor/src/RemoteConnection.c +++ b/ogl_editor/src/RemoteConnection.c @@ -34,7 +34,7 @@ #define SOCKET_ERROR -1 #endif -extern int clientIndex; +static int s_clientIndex; int s_socket = INVALID_SOCKET; int s_serverSocket = INVALID_SOCKET; static bool s_paused = false; @@ -94,7 +94,7 @@ int findTrack(const char* name) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void RemoteConnection_mapTrackName(const char* name, int index) +void RemoteConnection_mapTrackName(const char* name) { int count = s_nameLookup.count; @@ -102,7 +102,7 @@ void RemoteConnection_mapTrackName(const char* name, int index) return; s_nameLookup.hashes[count] = quickHash(name); - s_nameLookup.ids[count] = index; + s_nameLookup.ids[count] = s_clientIndex++; s_nameLookup.count++; } @@ -220,7 +220,7 @@ void RemoteConnection_updateListner() { rlog(R_INFO, "Connected to %s\n", inet_ntoa(client.sin_addr)); s_socket = clientSocket; - clientIndex = 0; + s_clientIndex = 0; RemoteConnection_sendPauseCommand(true); //RemoteConnection_sendSetRowCommand(trackView->getEditRow()); } diff --git a/ogl_editor/src/RemoteConnection.h b/ogl_editor/src/RemoteConnection.h index a0b4f5c..f23db03 100644 --- a/ogl_editor/src/RemoteConnection.h +++ b/ogl_editor/src/RemoteConnection.h @@ -28,5 +28,5 @@ void RemoteConnection_sendPauseCommand(bool pause); void RemoteConnection_sendSaveCommand(); void RemoteConnection_sendKeyFrames(const char* name, struct sync_track* track); -void RemoteConnection_mapTrackName(const char* name, int index); +void RemoteConnection_mapTrackName(const char* name); diff --git a/ogl_editor/src/TrackView.c b/ogl_editor/src/TrackView.c index b7f7354..df2574c 100644 --- a/ogl_editor/src/TrackView.c +++ b/ogl_editor/src/TrackView.c @@ -3,6 +3,9 @@ #include #include #include +#include "../../sync/sync.h" +#include "../../sync/data.h" +#include "../../sync/track.h" const int font_size = 12; static int start_pos = -19; @@ -43,13 +46,14 @@ static void printRowNumbers(int x, int y, int rowCount, int rowOffset, int rowSp /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/* -static void renderChannel(Channel* channel, int startX, int startY, int startPos, int endPos) +static void renderChannel(struct sync_track* track, int startX, int startY, int startPos, int endPos) { uint x, y; uint32_t color = Emgui_color32(40, 40, 40, 255); Emgui_drawBorder(color, color, startX, startY, 64, 600); + Emgui_drawText(track->name, startX + 2, startY + 2, Emgui_color32(0xff, 0xff, 0xff, 0xff)); + int y_offset = (startY + font_size) + font_size/2; if (startPos < 0) @@ -68,24 +72,15 @@ static void renderChannel(Channel* channel, int startX, int startY, int startPos int offset = startX + 6; float value = 0.0f; - bool set = false; + int idx = sync_find_key(track, y); - if (y < channel->maxRange) + if (idx >= 0) { - set = channel->set[y]; - value = channel->values[y]; - } + char temp[256]; + value = track->keys[idx].value; + snprintf(temp, 256, "% .2f", value); - if (set) - { - char valueText[16]; - - if (value < 0.0f) - sprintf(valueText, "%0.8f", value); - else - sprintf(valueText, "%8.4f", value); - - Emgui_drawText(valueText, offset, y_offset + (font_size / 2), Emgui_color32(255, 255, 255, 255)); + Emgui_drawText(temp, offset, y_offset + (font_size / 2), Emgui_color32(255, 255, 255, 255)); } else { @@ -114,21 +109,39 @@ static void renderChannel(Channel* channel, int startX, int startY, int startPos y_offset += font_size; } } -*/ - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void TrackView_render() +int doMax(int a, int b) { - //uint i = 0; //, channel_count = 10; + if (b >= a) + return b; + else + return a; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void TrackView_render(const TrackViewInfo* viewInfo, struct sync_data* syncData) +{ + // TODO: Calculate how many channels we can draw given the width + + uint i = 0; //, channel_count = 10; printRowNumbers(2, 42, 40, start_pos, font_size, 8); + if (syncData->num_tracks == 0) + return; + + int num_tracks = syncData->num_tracks; + + if (num_tracks > 4) + num_tracks = 4; + //i = 0; - //for (i = 0; i < channel_count; ++i) - // renderChannel(&s_testChannel, 40 + (i * 64), 20, start_pos, start_pos + 40); + for (i = 0; i < num_tracks; ++i) + renderChannel(syncData->tracks[i], 40 + (i * 64), 20, start_pos, start_pos + 40); uint32_t color = Emgui_color32(127, 127, 127, 56); diff --git a/ogl_editor/src/TrackView.h b/ogl_editor/src/TrackView.h index d315d72..0c3e87a 100644 --- a/ogl_editor/src/TrackView.h +++ b/ogl_editor/src/TrackView.h @@ -2,6 +2,8 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +struct sync_data; + typedef struct TrackViewInfo { int scrollPosY; @@ -14,5 +16,5 @@ typedef struct TrackViewInfo /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void TrackView_init(); -void TrackView_render(const TrackViewInfo* viewInfo); +void TrackView_render(const TrackViewInfo* viewInfo, struct sync_data* syncData);