Commits

kasicass committed 8cd2e84

commit some

  • Participants
  • Parent commits bb9d4d6

Comments (0)

Files changed (6)

 	src/resource/path.c										\
 	src/resource/image.c									\
 	src/util/resid.c											\
-	src/simpletest.c
+	src/drawing.c													\
+	src/main2.c
 
 CFLAGS  = -g -Wall -Isrc -I/usr/local/include
 LDFLAGS = -L/usr/local/lib -lSDL2
 
 ==== DONE ====
 2012-04-20
- + util/resid.h/.c (2 tomatoes)
+ + util/resid(.h/.c) (2 tomatoes)
 
 2012-04-15
  + JSON test (2 tomatoes)
 #include "drawing.h"
 #include "util/klist.h"
+#include "resource/resource.h"
 #include <assert.h>
 
 struct DrawItemInternal
 	K_LIST_INIT(&g_draw.drawList);
 }
 
-void D_shutdown();
+void D_shutdown()
 {
 	
 }
 
 void D_addItem(enum DLAYER layer, struct DrawItem data)
 {
-	struct DrawItemInternal *item = K_LIST_FIRST(g_draw.freeList);
+	struct DrawItemInternal *item = K_LIST_FIRST(&g_draw.freeList);
 	if (!item)
 	{
-		item = malloc(sizeof(*item));
+		item = (struct DrawItemInternal *) malloc(sizeof(*item));
 	}
 
-	item.data = data;
+	item->data = data;
 	K_LIST_INSERT_HEAD(&g_draw.drawList, item, entry);
 }
 
 static void D_drawItem(struct DrawItem *item)
 {
-	SDL_Surface *main = g_draw.surface;
-	SDL_BlitSurface(item
+	SDL_Surface *dst = g_draw.surface;
+	SDL_Surface *src = RC_getSurface(item->rid);
+	SDL_BlitSurface(src, &item->srcRect, dst, &item->destRect);
 }
 
 void D_endDrawing()
 		D_drawItem(&item->data);
 	}
 
-	g_draw.freeList = g_draw.drawList;
+	g_draw.freeList.lh_first = g_draw.drawList.lh_first;
+	K_LIST_INIT(&g_draw.drawList);
 }
 
 #ifndef THESWORD2_DRAWING_H
 #define THESWORD2_DRAWING_H
 
+#include "util/resid.h"
 #include <SDL2/SDL.h>
 
 enum DLAYER
+#include <SDL2/SDL.h>
+#include <assert.h>
+#include "drawing.h"
+
+void myDraw()
+{
+	struct DrawItem item;
+
+	D_beginDrawing();
+
+	item.rid = RSTR_toRESID(RSTR_alloc("image/blacksmith.bmp"));
+	item.srcRect.x = item.srcRect.y = 0;
+	item.srcRect.w = item.srcRect.h = 50;
+	item.destRect.x = item.destRect.y = 50;
+	item.destRect.w = item.destRect.h = 50;
+
+	D_addItem(LAYER_MAP_1, item);
+
+	D_endDrawing();
+}
+
+int main()
+{
+	int result;
+	SDL_Window *win1 = NULL;
+	SDL_Renderer *renderer = NULL;
+	SDL_Event event;
+
+	result = SDL_Init(SDL_INIT_VIDEO);
+	assert(result == 0);
+
+	win1 = SDL_CreateWindow("#1", 100, 100, 800, 600, SDL_WINDOW_SHOWN);
+	assert(win1 != NULL);
+
+	renderer = SDL_CreateRenderer(win1, -1, SDL_RENDERER_ACCELERATED);
+	assert(win1 != NULL);
+
+	D_init(renderer, 800, 600);
+
+	while (true)
+	{
+		if (SDL_PollEvent(&event))
+		{
+			if (event.type == SDL_QUIT)
+				break;
+		}
+
+		myDraw();
+	}
+
+	SDL_DestroyRenderer(renderer);
+	SDL_DestroyWindow(win1);
+	SDL_Quit();
+	return 0;
+}

doc/mapformat.txt

+# tilewidth  : 32
+# tileheight : 32
+
 {
-	"tilewidth"  : 96,
-	"tileheight" : 96,
   "images"  : [
 		"tiles/map01.bmp",
 		"tiles/map02.bmp",