Free Hero Mesh

Check-in [81f52e6f42]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Add some SQL functions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 81f52e6f42fc9ac97ad167bba91cb5b06f7cff31
User & Date: user on 2018-06-10 16:34:34
Other Links: manifest | tags
Context
2018-06-10
21:26
Fill in the VARIABLES table check-in: fd3a87fc50 user: user tags: trunk
16:34
Add some SQL functions check-in: 81f52e6f42 user: user tags: trunk
06:10
Move around some BEGIN and COMMIT commands to avoid misnested transactions in some cases check-in: b4a4337c4a user: user tags: trunk
Changes

Modified compile from [4085df24bd] to [626fabb32d].

1
2
3

4
5
6
7
8
9
10
11

12
13
14
15
16

17
18
1
2

3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19


-
+







-
+





+


#!/bin/bash --
test -f CFLAGS || echo xxx > CFLAGS
test "xx$CFLAGS" = "x`cat CFLAGS`" || rm bindings.o class.o picture.o
test "xx$CFLAGS" = "x`cat CFLAGS`" || rm bindings.o class.o picture.o function.o
echo "x$CFLAGS" > CFLAGS
test "x$EXE" = "x" && EXE=~/bin/heromesh
test instruc -nt instruc.h && node instruc.js > instruc.h
test instruc.js -nt instruc.h && node instruc.js > instruc.h
test names.js -nt names.h && node names.js > names.h
test quarks -nt quarks.h && node quarks.js > quarks.h
test quarks.js -nt quarks.h && node quarks.js > quarks.h
test heromesh.h -nt "$EXE" && rm bindings.o class.o picture.o
test heromesh.h -nt "$EXE" && rm bindings.o class.o picture.o function.o
test instruc.h -nt "$EXE" && rm class.o
test pcfont.h -nt "$EXE" && rm picture.o
test quarks.h -nt "$EXE" && rm bindings.o picture.o
test bindings.c -nt bindings.o && bash bindings.c
test class.c -nt class.o && bash class.c
test function.c -nt function.o && bash function.c
test picture.c -nt picture.o && bash picture.c
bash main.c

Added function.c version [7c083f4652].
























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#if 0
gcc ${CFLAGS:--s -O2} -c function.c `sdl-config --cflags`
exit
#endif

#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"

static void fn_basename(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_text(cxt,basefilename,-1,SQLITE_STATIC);
}

static void fn_cacheid(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_int64(cxt,*(sqlite3_int64*)sqlite3_user_data(cxt));
}

static void fn_modstate(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_int(cxt,SDL_GetModState());
}

static void fn_picture_size(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_int(cxt,picture_size);
}

static void fn_resource(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  int i;
  if(argc>14 || argc<1) {
    sqlite3_result_error(cxt,"Invalid number of XRM resource components",-1);
  } else {
    for(i=0;i<argc;i++) optionquery[i+1]=xrm_make_quark(sqlite3_value_text(argv[i])?:(const unsigned char*)"?",0)?:xrm_anyq;
    sqlite3_result_text(cxt,xrm_get_resource(resourcedb,optionquery,optionquery,argc+1),-1,SQLITE_TRANSIENT);
  }
}

static void fn_sign_extend(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_int64 a;
  if(sqlite3_value_type(*argv)==SQLITE_NULL) return;
  a=sqlite3_value_int64(*argv)&0xFFFFFFFF;
  sqlite3_result_int64(cxt,a-(a&0x80000000?0x100000000LL:0));
}

void init_sql_functions(sqlite3_int64*ptr0,sqlite3_int64*ptr1) {
  sqlite3_create_function(userdb,"BASENAME",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_basename,0,0);
  sqlite3_create_function(userdb,"LEVEL_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr0,fn_cacheid,0,0);
  sqlite3_create_function(userdb,"MODSTATE",0,SQLITE_UTF8,0,fn_modstate,0,0);
  sqlite3_create_function(userdb,"PICTURE_SIZE",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_picture_size,0,0);
  sqlite3_create_function(userdb,"RESOURCE",-1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_resource,0,0);
  sqlite3_create_function(userdb,"SIGN_EXTEND",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_sign_extend,0,0);
  sqlite3_create_function(userdb,"SOLUTION_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr1,fn_cacheid,0,0);
}

Modified heromesh.h from [e6403c7a41] to [fe8a013d87].

118
119
120
121
122
123
124




118
119
120
121
122
123
124
125
126
127
128







+
+
+
+
    const char*txt;
  };
} UserCommand;

void load_key_bindings(void);
const UserCommand*find_key_binding(SDL_Event*ev,int editing);

// == function ==

void init_sql_functions(sqlite3_int64*ptr0,sqlite3_int64*ptr1);

Modified main.c from [8ee65d5a1a] to [56dbbbf3e1].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







#if 0
gcc ${CFLAGS:--s -O2} -o ${EXE:-~/bin/heromesh} main.c class.o picture.o bindings.o smallxrm.o sqlite3.o `sdl-config --cflags --libs` -ldl -lpthread
gcc ${CFLAGS:--s -O2} -o ${EXE:-~/bin/heromesh} main.c class.o picture.o bindings.o function.o smallxrm.o sqlite3.o `sdl-config --cflags --libs` -ldl -lpthread
exit
#endif

/*
  This program is part of Free Hero Mesh and is public domain.
*/

308
309
310
311
312
313
314

315
316
317
318
319
320
321
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322







+







    if(*s && sqlite3_load_extension(userdb,s,0,&p)) fatal("Failed to load extension '%s' (%s)\n",s,p?:"unknown error");
    free(s);
  }
  if(sqlite3_exec(userdb,schema,0,0,&s)) fatal("Failed to initialize database schema (%s)\n",s?:"unknown error");
  optionquery[1]=Q_sqlInit;
  v=xrm_get_resource(resourcedb,optionquery,optionquery,2);
  if(v && sqlite3_exec(userdb,v,0,0,&s)) fatal("Failed to execute user-defined SQL statements (%s)\n",s?:"unknown error");
  init_sql_functions(&leveluc,&solutionuc);
}

void set_cursor(int id) {
  id>>=1;
  if(!cursor[id]) cursor[id]=SDL_CreateCursor((void*)cursorimg+(id<<6),(void*)cursorimg+(id<<6)+32,16,16,cursorhot[id]>>4,cursorhot[id]&15);
  SDL_SetCursor(cursor[id]);
}